How to create JSON file
Now, we are quite familiar with some things, like what is JSON, and why should we use it. But now, we are going to have a look at how can we create our first JSON file. Well, it is very easy, but you just need to be familiar with what extension we need to use.
You might have seen some different extensions for different files, like .pdf, .xlsx, .txt, .rtf, and a lot more. So, just like this, here as well, we are going to require some file extension over here, which is .json. For example, gyanipandit.json would be a JSON file. Now, let’s head to creating some JSON files.
(We have used Visual Studio code throughout the session, but if you are manually creating a file, to change the extension, you may need to check the box in the view tab in the explorer, which says file name extensions. This will show the file extension, and enable you to change the file extension)
- Step 1: We recommend creating all the files in a particular folder, for this course. So, you can just create a folder in your system.
- Step 2: After creating the folder, you have to create a file there, and change its extension, to .json. For example, we can create a file, with the name gyanipandit.json.
Note: We use different file extensions for different files, like .java, .py, .pdf, .txt. So, just like this, we have an extension .json for the JSON file.
- Step 3: So here, after naming the file, you just need to press the enter key and your first JSON file will be created.
In this way, we can simply create a JSON file. Once we have the JSON file with us, we are going to write some data to it. But now the question comes, how can we write data here? What is the syntax here? So now, we are going to head towards the syntax.