Working with JSON for Web Development

This chapter will help you to learn JSON fundamentals, example, syntax, array, object, encode, decode, file, date and date format. You will also be able to learn JSON examples with other technologies such as Java and PHP.

JSON Syntax


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).

See this 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.