JSON – JavaScript Object Notation

JSON – JavaScript Object Notation

In this blog we are going to explain about JSON – JavaScript Object Notation . Let us discuss it below :

_______________________________________________________________________________

                                              JSON – JavaScript Object Notation

It is similar to XML language. The communication between the client and server can also done by JSON format.

In JSON, values must be one of the following data types:

  • a string
  • a number
  • an object (JSON object)
  • an array
  • a boolean
  • null
    Numbe

    double- precision floating-point format in JavaScript

     

    2  

     String

    double-quoted Unicode with backslash escaping

    3 Boolean

    true or false

    4 Array

    an ordered sequence of values

    5 Value

    it can be a string, a number, true or false, null etc

    6 Object

    an unordered collection of key:value pairs

    7 Whitespace

    can be used between any pair of tokens

    8 null

    empty

    Number

    • It is a double precision floating-point format in JavaScript and it depends on implementation.
    • Octal and hexadecimal formats are not used.
    • No NaN or Infinity is used in Number.

    The following table shows the number types −


    1 Number

    double- precision floating-point format in JavaScript

    2 String

    double-quoted Unicode with backslash escaping

    3 Boolean

    true or false

    4 Array

    an ordered sequence of values

    5 Value

    it can be a string, a number, true or false, null etc

    6 Object

    an unordered collection of key:value pairs

    7 Whitespace

    can be used between any pair of tokens

    8 null

    empty

    Number

    • It is a double precision floating-point format in JavaScript and it depends on implementation.
    • Octal and hexadecimal formats are not used.
    • No NaN or Infinity is used in Number.

    The following table shows the number types −

    S. No. Type & Description
    1 Integer

    Digits 1-9, 0 and positive or negative

    2 Fraction

    Fractions like .3, .9

    3 Exponent

    Exponent like e, e+, e-, E, E+, E-

    Syntax

    var json-object-name = { string : number_value, .......}

    In JavaScript values can be all of the above, plus any other valid JavaScript expression, including:

  • a function
  • a date
  • undefined
  • Let’s have a quick look at the basic syntax of JSON. JSON syntax is basically considered as a subset of JavaScript syntax; it includes the following −
    • Data is represented in name/value pairs.
    • Curly braces hold objects and each name is followed by ‘:'(colon), the name/value pairs are separated by , (comma).
    • Square brackets hold arrays and values are separated by ,(comma).

    Below is a simple example −

    {
       "book": [
    
          {
             "id": "01",
             "language": "Java",
             "edition": "third",
             "author": "Herbert Schildt"
          },
    
          {
             "id": "07",
             "language": "C++",
             "edition": "second",
             "author": "E.Balagurusamy"
          }
    
       ]
    }

    JSON supports the following two data structures −

    • Collection of name/value pairs − This Data Structure is supported by different programming languages.
    • Ordered list of values − It includes array, list, vector or sequence etc.

 

 It is string with certain format. The format is easy to follow and very important. The arrangements are key and values,

“name”:”payilagam”

In the above example, name is key and payilagam is value. If you have more than one data, we can arrange it in comma separate,

“name”:”payilagam”,”place”:”chennai”

 

In above example has collection object, it should be hold it in the curly braces.

{“name”:”payilagam”,”place”:”chennai”}

Reference: www.w3schools.com