Tuesday, April 7, 2020

Structures of JSON

Description
In this page you will learn about structures of JSON. you will also learn different forms of storing data in JSON.

Data Structures supported by JSON

JSON supports two widely used (amongst programming languages) data structures.
A collection of name/value pairs. Different programming languages support this data structure in different names. Like object, record, struct, dictionary, hash table, keyed list, or associative array.
An ordered list of values. In various programming languages, it is called as array, vector, list, or sequence.
Since data structure supported by JSON is also supported by most of the modern programming languages, it makes JSON a very useful data-interchange format.

Data Types in JSON

JSON supports an array of data types. We will discuss those in detail in the following section of this page of the JSON tutorial.

Object

Syntax:
{ string : value, .......}
Explanation of Syntax
An object starts and ends with '{' and '}'. Between them, a number of string value pairs can reside. String and value is separated by a ':' and if there are more than one string value pairs, they are separated by ','.
Example
{
  "firstName": "Bidhan",
  "lastName": "Chatterjee",
  "age": 40,
  "email":"bidhan@example.com"
     }

In JSON, objects can nest arrays (starts and ends with '[' and ']') within it. The following example shows that.
 {
  "Students": [
  
     { "Name":"Amit Goenka" ,
  "Major":"Physics" }, 
     { "Name":"Smita Pallod" ,
  "Major":"Chemistry" }, 
     { "Name":"Rajeev Sen" , 
  "Major":"Mathematics" }
     ]
     }

Array:

Syntax:
[ value, .......]
Explanation of Syntax:
An Array starts and ends with '[' and ']'. Between them, a number of values can reside. If there are more than one values reside, they are separated by ','.
Example
[100, 200, 300, 400]
If the JSON data describes an array, and each element of that array is an object.
[
     {
  "name": "Bidhan Chatterjee",
  "email": "bidhan@example.com"
     },
     {
  "name": "Rameshwar Ghosh",
  "email": "datasoftonline@example.com"
     }
     ]
Remember that even arrays can also be nested within an object. The following shows that.
 {
  "firstName": "Bidhan",
  "lastName": "Chatterjee",
  "age": 40,
  "address":
     {
  "streetAddress": "144 J B Hazra Road",
  "city": "Burdwan",
  "state": "Paschimbanga",
  "postalCode": "713102"
     },
  "phoneNumber":
     [
     {
  "type": "personal",
  "number": "09832209761"
     },
     {
  "type": "fax",
  "number": "91-342-2567692"
     }
       ]
 }

Value

Syntax:
String || Number || Object || Array || TRUE || FALSE || NULL
A value can be a string, a number, an object, an Array, a Boolean value (i.e. true or false) or Null. This structure can be nested.

String

A string is a sequence of zero or more Unicode characters, enclosed by double quotes, using backslash escapes. A character is represented as a single character string, similar to a C or Java string.
The following table shows supported string types.
String TypesDescription
"A double quotation mark.
\Reverse Solidus
/Solidus
bBackspace
fform feed
nnewline
rCarriage return
tHorizontal tab
uFour hexadecimal digits

Number

The following table shows supported number types.
Number TypesDescription
IntegerPositive or negative Digits.1-9. And 0.
FractionFractions like .8.
Exponente, e+, e-, E, E+, E-

Whitespace

Whitespace can be placed between any pair of supported data-types.

No comments:

Post a Comment

Structures of JSON

Description In this page you will learn about structures of JSON. you will also learn different forms of storing data in JSON. Data ...