Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the basic syntax of JSON

Shulou Source: shulou.com Published: 2022-06-01 19:09:17 10月01日 Update

This article mainly introduces the relevant knowledge of "what is the basic grammar of JSON". The editor shows you the operation process through an actual case. The method of operation is simple, fast and practical. I hope this article "what is the basic grammar of JSON" can help you solve the problem.

JSON: JavaScript Object Notation (JavaScript object representation), JSON is the syntax for storing and exchanging text information, similar to XML,JSON, which is smaller, faster, and easier to parse than XML.

JSON grammar rules

The JSON syntax is a subset of the syntax represented by JavaScript objects.

Data in name / value pairs data is separated by commas in curly braces save objects in parentheses save array JSON name / value pairs

The writing format of JSON data is: name / value pair.

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

"name": "Rookie course"

This is easy to understand and is equivalent to this JavaScript statement:

Name = "rookie tutorial" JSON value

The JSON value can be:

Numeric (integer or floating point) string (in double quotes) logical values (true or false) array (in square braces) objects (in curly braces) nullJSON digits

JSON numbers can be integer or floating point:

{"age": 30} JSON object

The JSON object is written in curly braces ({}):

An object can contain multiple name / value pairs:

{"name": "Rookie tutorial", "url": "www.runoob.com"}

This is also easy to understand and is equivalent to this JavaScript statement:

Name = "rookie tutorial" url = "www.runoob.com" JSON array

The JSON array is written in square brackets:

An array can contain multiple objects:

{"sites": [{"name": "Rookie tutorial", "url": "www.runoob.com"}, {"name": "google", "url": "www.google.com"}, {"name": "Weibo", "url": "www.weibo.com"}]}

In the above example, the object "sites" is an array of three objects. Each object represents a record about a website (name, url).

JSON Boolean value

The JSON Boolean value can be true or false:

{"flag": true} JSON null

JSON can set the null value:

{"runoob": null} JSON uses JavaScript syntax

Because JSON uses the JavaScript syntax, no additional software is needed to handle JSON in JavaScript.

With JavaScript, you can create an array of objects and assign values like this:

Example

Var sites = [{"name": "runoob", "url": "www.runoob.com"}, {"name": "google", "url": "www.google.com"}, {"name": "Weibo", "url": "www.weibo.com"}]

You can access the first item in the array of JavaScript objects like this (the index starts at 0):

Sites [0] .name

The returned content is:

Runoob

You can modify the data like this:

Sites [0] .name = "Rookie tutorial"

JSON file the file type of the JSON file is ".json" the MIME type of the JSON text is "application/json" about "what is the basic syntax of JSON". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Tags: Objects grammars arrays names tutorials rookie tutorials rookies data basics parentheses numbers files knowledge brackets content multiple Boolean quotation marks text equivalence Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Huawei Microsoft vpn Linux