JSON

JSON

Petra and Valerie

Definition:

JavaScript Object Notation

Attribute-Value pair

Basic data types: string, number, boolean, array, object


Example:

{

 "people": [

   {

     "name": "Zelda",

     "age": 17,

     "isPrincess": true,

     "horse": {

         "type": "royal",

         "color": "white"

     }

   },

   {

     "name": "Link",

     "age": 18,

     "isPrincess": false,

     "horse": {

         "type": "normal",

         "color": "brown"

     }

   }

 ]

}




Pros:

  • is smaller than corresponding XML
  • a very good fit for browsers and a natural way to evolve the platform due to its close relationship with JavaScript (any JSON data can be imported in a website)
  • human-readable
  • compact and structured (strings, booleans are represented differently and can be easily distinguished; also between single items and collections)
  • supports schemas (for specifying the format of a document) and namespace support (mixing data read or written by different sources)
  • has a simple syntax
  • is parsing faster than XML
  • language independent → all modern programming languages support and can generate and parse JSON

Cons:

  • JSON is intended only for describing data as an object hierarchy, while XML has many other features as well.


Where do we use it?

  • NoSql database
  • JavaScript backend


Report Page