JSON

JSON stands for JavaScript Object Notation and is simply a data representation format. It is a lightweight format for storing and transporting data. JSON is “self-describing” and easy to understand. JSON file format that is used for sending, receiving, and storing data from the same or different systems in a network. It is used in the REST request and response API (Application Program Interface) services.

Why do we use JSON?

It is a Language-Independent format that is derived from JavaScript. It is a lightweight text-based data interchange format which means, it is easy to read and write when compared to XML. This type of file provides a human-readable format for storing and manipulating data when developers build software.

1. Readable

The JSON structure is easily readable and straightforward.

2. Faster

The JSON parsing process is faster than that of the XML because the DOM manipulation library in XML requires extra memory for handling large XML files. However, JSON requires less data which ultimately results in reducing the cost and increasing the parsing speed.

3. Structured Data

JSON uses a map data structure and XML uses a tree structure. JSON natively supports six data types: string, number, Boolean, null, object, and array. A JSON number is a Double Binary Floating Point Number.

4. Less Verbose

JSON follows a compact style to improve its users’ readability. While working with a complex system, JSON tends to make substantial enhancements.

Example of JSON

{
  "status": 200,
  "message": "Success",
  "noOfItems": 1,
  "addresses": [
      {
        "line_1": "House Of Commons",
        "line_2": "Houses Of Parliament",
        "line_3": "",
        "post_town": "LONDON",
        "postcode": "SW1A 0AA",
        "address": "House Of Commons, Houses Of Parliament, LONDON, SW1A 0AA"
      }
    ]
}

JSON Syntax Rules

  • Data is represented in name/value pairs
  • Data is separated by commas
  • Curly braces {} hold the objects
  • Square brackets [] hold the arrays
  • The file extension should be .json