Basic Syntax
Now, we are going to have a look at the basic syntax, which is going to help us, while we would write some data in our JSON file. The basic thing is that JSON is language-independent, but many of the things are conventionally taken from many popular languages like C, Java, Python, JavaScript, and many others.
The basic thing is that the data is written as key-value pairs or name-value pairs. So, there would be the name, or key, followed by a colon, and a value associated with the key or name. For example, the name can be “color”, and the value associated with the key can be some color, like “blue”, or some other color.
So, here are some of the points, which can make us understand the syntax.
- The data is in the key-value pairs.
- When we have multiple data, the data will be separated by a comma.
- We have curly braces to hold the objects.
- We have the square brackets hold arrays.
- The values can be of different datatypes, which we are going to learn about ahead.
Here is a basic syntax for the JSON data.
“name” : “GyaniPandit”
Here, the name is the key, and the value associated with the key is “GyaniPandit”.
So, basically, we can consider that the key can be something like name, age, address, email, city, designation, or any other data on the basis of requirement. In the above example, you can see, that the name is the key, and the value associated with that key is “GyaniPandit”. The value basically is some kind of valid data. We are soon going to learn about valid data in this course.