JavaScript object notation

JSON, or JavaScript object notation, is a standard data format that is used in REST APIs and microservices. It can be read by humans but also by machines. So, humans can actually understand the values and, also, machines can automatically parse the data. The data objects consist of attribute-value pairs and array data types. The data type values supported are number, string, Boolean, array, object, and null, as shown in the following code:

{
  "firstName": "John",
  "lastName": "Smith",
  "age": 27,
  "address": {
    "city": "New York",
    "postalCode": "10021"
  },
  "phoneNumbers": [
    {
      "type": "home",
      "number": "212 555-1234"
    },
    {
      "type": "mobile",
      "number": "123 456-7890"
    }
  ]
}

The preceding code is an example of details related to John Smith. You can see the first name is the key and the string value is John. In that way, you have two strings separated by a colon. So, you see that John Smith is 27 years old and the city he lives in is New York, with the postal code 10021, and you can see that he has two phone numbers. One is his home phone number and the other one is a mobile phone number. JSON is very descriptive and can easily be parsed programmatically.

You can see that it doesn't have to be flat either. It can also be hierarchical and has the keys built into the data. You can also very easily add new phone numbers to JSON data and extend the schema, without breaking the model, unlike other formats such as comma-separated variable (CSV) files. JSON is supported natively in the standard Python JSON library, but you can also use other libraries. What I like about it is that there is native mapping to Python data types.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset