Web Programming TutorialsJSON Fundamentals

JSON Fundamentals

In the last session we had an introduction to XML Fundamentals. Like XML, JSON is also used to store a structured data. So today we will have an introduction to JSON Fundamentals.

  • What is JSON?
    • JSON stands for Javascript Object Notation.
    • It is a lightweight data interchange format.
    • It is easy for humans to read and write.
    • It is a text based open standard, designed for human readable data. It is readable only if it is formatted properly.
    • It uses name/value pairs to store data.
    • It has same value types as javascript.
    • It works like XML and is an alternative to XML.
    • It is not possible to decide which one is better, XML or JSON; because there are certain areas where XML is a better choice and certain other areas where JSON is a better choice.

    Let’s understand the syntax of JSON in this JSON Fundamentals tutorial.

  • JSON Syntax
    • In JSON all data is formatted in name/value pairs.
    • Example of a name/value pair is as shown below:
    • “firstname” : “Brad”

    • In the above example : firstname is the name, then we have a colon and then the value Brad. The name and value must be enclosed in the double quotes.
    • If you have more data i.e. more than one name/value pairs, they are separated using comma. Eg: “firstname” : “Brad” , “lastname” : “Dixon”.
    • JSON objects are contained in curly braces ({}).
    • JSON arrays are contained in brackets ([]).
    • JSON files have a .json extension.
    • The MIME type is “application/json”.
  • JSON Object
    • Here, we have shown an example of JSON Object for a user with 3 properties:
    • {
      	“firstName” : “Brad” ,
      	“lastName” :  “Traversy” ,
      	“email”  : “[email protected]”
    • We know that JSON objects are contained in curly braces, so we have the object in curly braces in the above example.
    • The object has 3 name/value pairs which are its properties separated by comma.
  • JSON Array
    • An example of array is shown below:
    • {
      	“pets” : [
      			   {“name” : “jack” , “animal” : “dog”},
      			   {“name” : “john” , “animal” : “cat”},
      			   {“name” : “joe” , “animal” : “fish”}
    • We have shown an array named “pets”, which holds 3 JSON objects.
    • Each object is a record of a pet with a name and the type of animal it is.
  • XML vs. JSON
    • JSON:
      • JSON is more lightweight than XML.
      • It is more simple.
      • Since JSON is lightweight, it is more faster than XML.
      • It is a little easier to read.
      • JSON is native to javascript.
    • XML:
      • XML is more extensible.
      • It is more flixible.
      • It is more complicated compared to JSON.
      • It offers more compatibility between systems.

      JSON is generally preffered over XML on most of the occasions.

This was all about JSON Fundamentals.


Please enter your comment!
Please enter your name here

Exclusive content

- Advertisement -

Latest article


More article

- Advertisement -