HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
The JSON syntax is a subset of the JavaScript syntax
JSON syntax is derived from JavaScript object notation syntax:
JSON data is written as name/value pairs (aka key/value pairs).
A name/value pair consists of a field name (in double quotes), followed by a colon, followed by a value:
"name":"John"
JSON names require double quotes.
The JSON format is almost identical to JavaScript objects.
In JSON, keys must be strings, written with double quotes:
{"name":"John"}
In JavaScript, keys can be strings, numbers, or identifier names:
{name:"John"}
In JSON, values must be one of the following data types:
In JavaScript values can be all of the above, plus any other valid JavaScript expression, including:
In JSON, string values must be written with double quotes:
{"name":"John"}
In JavaScript, you can write string values with double or single quotes:
{name:'John'}
Because JSON syntax is derived from JavaScript object notation, very little extra software is needed to work with JSON within JavaScript.
With JavaScript you can create an object and assign data to it, like this:
person = {name:"John", age:31, city:"New York"};
You can access a JavaScript object like this:
// returns John
person.name;
It can also be accessed like this:
// returns John
person["name"];
Data can be modified like this:
person.name = "Gilbert";
It can also be modified like this:
person["name"] = "Gilbert";
You will learn how to convert JavaScript objects into JSON later in this tutorial.
The same way JavaScript objects can be written as JSON, JavaScript arrays can also be written as JSON.
You will learn more about objects and arrays later in this tutorial.