WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

JSON Syntax


JSON syntax is a subset of JavaScript syntax.


JSON syntax rules

JSON syntax is a subset of the JavaScript object representation syntax.

  • Data is in name /value pairs
  • Comma separated data
  • Braces save objects
  • Square brackets hold array

JSON name /value pairs

JSON data is written in the following format: name /value pairs.

The name /value pair includes the field name (in double quotes), followed by a colon, and then the value:

Example

"firstName":"John"

JSON value

JSON values can be:

  • Number (integer or floating point)
  • String (in double quotes)
  • Logical value (true or false)
  • Array (in square brackets)
  • Object (in braces)
  • null

JSON Objects

JSON objects are composed inside wavy braces.

Just like JavaScript, JSON articles can contain different name/values pairs:

Example

{"firstName":"John", "lastName":"Doe"}

JSON Arrays

JSON clusters are composed inside square brackets.

Just like JavaScript, a JSON cluster can contain different objects:

Example

"employees":[
    {"firstName":"John", "lastName":"Doe"},
    {"firstName":"Anna", "lastName":"Smith"},
    {"firstName":"Peter","lastName":"Jones"}
]

In the precedent over, the item "employees" is a cluster containing three objects. Each item is a record of an individual (with a first name and a last name).


JSON Uses JavaScript Syntax

Because JSON punctuation is gotten from JavaScript object documentation, next to no additional programming is expected to work with JSON inside JavaScript.

With JavaScript you can make a variety of items and relegate information to it, as this:

Example

var representatives = [
    {"firstName":"John", "lastName":"Doe"},
    {"firstName":"Anna", "lastName":"Smith"},
    {"firstName":"Peter","lastName": "Jones"}
];

The first passage in the JavaScript object exhibit can be gotten to like this:

Example

/returns John Doe
employees[0].firstName + " " + employees[0].lastName;

It can likewise be gotten to like this:

Example

/returns John Doe
employees[0]["firstName"] + " " + employees[0]["lastName"];

Data can be altered like this:

Example

employees[0].firstName = "Gilbert";

You can modify the data like this:

Example

employees[0]["firstName"] = "Gilbert";

In the following section you will figure out how to change over a JSON content to a JavaScript object.


JSON file

  • The file type of the JSON file is ".json"
  • MIME type of JSON text is "application /json"


Welookups is optimized for learning.© kumar aditya singh .
All Right Reserved and you agree to have read and acceptedour term and condition.
All Rights Reserved.

welookups.com
Spring - Bean Definition