Understanding JSON – Part 1, Definition

While JSON does sound comically similar to the name Jason, JSON actually stands for JavaScript Object Notation. JSON is format for storing and transporting data across applications.

JSON is completely language independent. That means, any language can prepare and read data in JSON format. The most popular scenario of using JSON is by making API calls request and receiving response from the server.

JSON Data can be represented as key/value pairs. For example, a key name in double quotes, followed by colon and value to that key:

"trainNumber" : 12055

The value of key trainNumber is an Integer.

JSON Objects, are represented with {} (curly) braces. A JSON Object can contain more than one key/value pair, separated by comma (,). For example:

{"trainNumber":12055,"trainName":"NDLS DEHRADUN JAN SHATABDI"}

JSON Arrays, are represented like a regular array with [] (square) brackets. A JSON Array can contain more than one JSON Object, separated by comma (,). For example:

"trains":[
{"trainNumber":12055,"trainName":"NDLS DEHRADUN JAN SHATABDI"},
{"trainNumber":12013,"trainName":"NDLS ASR SHATABDI EXPRESS"},
{"trainNumber":12005,"trainName":"NDLS KAL SHATABDI EXPRESS"}
]

So, the above block consists of a JSON Array with 3 JSON Objects. Each JSON Object has 2 key/value pairs, which are trainNumber and trainName.

Now, that the basics of JSON is clear, in next parts, we’ll learn how to prepare and read JSON Arrays and Objects.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *