I'd be more frightened by not using whatever abilities I'd been given. I'd be more frightened by procrastination and laziness. -Denzel Washington
Douglas Crockford originally specified the JSON format in the early 2000s.
Since the JSON format is text only, it can easily be sent to and from a server, and used as a data format by any programming language.
The structure of JSON is based on two basic structures,
A collection of key / value pairs.
An ordered list of values.
Also, there are six data types allowed in JSON, and they include:
- In JSON, the six data types which are supported will take their various forms.
From the above example, the name is set as string which has a double quote for both the key and the value, age is set as number, the address is included in an object, in the address object, the key cop is set as a boolean, car is null and hobbies is set as an array.
- In JSON, it is strictly forbidden to make use of comments inside the file.
The above code in the data.json file will give us an error because of the comment in the code.
Functions or methods are not allowed in JSON as they only support data format.
- Keys are not needed to be covered in double quotes and only the values are required to be covered in double quotes.
From the above code, amount is a method of the member object, which contains data that is stored in the object property.
It is better to use primitive data types (string, number, boolean, null, undefined, symbol), as they are faster and not complex.
obj is now a string. Also JSON.stringify() is supported by all major browsers.
To get more free content on web development, subscribe to my newsletter: