In this quick dive, we aim to gain a basic understanding of JSON; particularly its syntax.
JSON stands for "Javascript Object Notation". It is a lightweight data-interchange format that is used to store and exchange data, especially on the web. The JSON syntax is based on the syntax of JavaScript objects, it is quite easy to master and can be used with any programming language. To write JSON,
First, create a JSON file ending in the extension
.json
Represent your data as a set of key-value pairs within curly braces
{}
Keys should be separated from values by a colon
:
key-value pairs should be separated from each other by a comma
,
Keys must be strings and must be surrounded by double quotes
""
Values can be strings, numbers, objects
{}
, arrays[]
, or one of the special valuestrue
,false
, ornull
If values are strings, they should also be surrounded by double quotes
""
If values are objects, they must also be represented as key-value pairs that follow JSON rules
Lastly and unfortunately, comments are not permitted in JSON
Here's an example representing user data in JSON:
{
"name": "John Doe",
"age": 30,
"isEmployed": true,
"skills": ["JavaScript", "HTML", "CSS"],
"address": {
"street": "123 Main St",
"city": "San Francisco",
"state": "CA"
}
}
๐๐That will be all for this Quick-Dive. Do leave comments if you found it helpful.