Learn About The Basic Syntax Statements in JSON

0
1827
Basic Syntax Statements

Basic Syntax Statements

In the last chapter, we discussed the characteristics and applications of JSON data format along with its overview and examples. In this chapter, we are going to discuss the basic syntaxes of JSON (JavaScript Object Notation). The syntaxes in JSON are considered as a subset of the JavaScript syntaxes. JSON syntaxes contain the following.

• Data in JSON is always represented as a name and value pairs (e.g., “subject”: “Java Programming”).
• Curly braces are used to hold objects and the ‘:’ (colon) is placed between each name and value pair. Multiple name-value pairs inside the curly braces are separated by , (comma).
• Square brackets are used to hold arrays. The name-value pairs in an array are separated by , (comma).

Lets take a recap on the JSON data format which we used in the last chapter to store the information related to the students for the various courses in a university.

Explanation of the JSON data format.
• Student is used as an array as it starts and closes by the Square brackets and holds values for 5 student records.
• Each student record starts and ends with the curly braces. Multiple curly braces within arrays are separated by , (comma).
• Between each curly braces, there are 5 name-value pairs where names are rollnum, subject, name, course, and university. Each student has different values for these 5 keys.
• All above name-value pairs are separated by ‘:’ (colon) and each such pairs within curly braces by , (comma).

Data Structure supported by JSON
JSON data format provides support for the following two types of data structures.
Name-value pairs as collection: – It is the most common type of Data Structure used for JSON which is supported by different programming languages such as JavaScript, C, C++, PHP, Python, PERL, Ruby, Java/J2EE, etc.
Ordered list of values: − It is type of data structure that includes array, vector or sequence, list, etc.

Examples:
1. Let’s take an example for JSON which has the “path” constructor option and JSON Array with objects as elements.

Conclusion: –
In this chapter, we discussed the JSON syntaxes along with their implementation of it in a bakery shop as an example.

LEAVE A REPLY

Please enter your comment!
Please enter your name here