DEV Community

Cover image for Things to know as a Beginner in JSON.
Coder Pink
Coder Pink

Posted on • Edited on

Things to know as a Beginner in JSON.

Things to remember...

  1. JSON stands for JavaScript Object Notation.

  2. JSON is very lightweight as compared to XML.

  3. It is text format for storing and retrieving data.

  4. It is human readable and easy to understand.

  5. It is very good to use JSON rather than XML.

  6. With JSON, can easily integrate with JavaScript.

  7. The file type for JSON files is ".json"


example of JSON...

'{"name":"Tae", "age":26, "bike":null, "isGood" : true}'
Enter fullscreen mode Exit fullscreen mode

in the above example, we can see that JSON is like an object that has key-value pairs. you have to enclose the JSON object with backticks(``).

It can take values as numbers, strings, null, Boolean, array and object.
You can also store an array in array, object in arrays as long as it is readable.

``



newJson = '{"name":"Tae", "age":26, "bike":null, "isGood" : true}'

//'{"name":"Tae", "age":26, "bike":null, "isGood" : true}'

parsedJson = JSON.parse(newJson)

// {name: 'Tae', age: 26, bike: null, isGood: true}

parsedJson['age']

//26

parsedJson["isGood"]

//true


Enter fullscreen mode Exit fullscreen mode


``

Store json object in new variable named newJson.

parse the jSON object so that you will get the JavaScript object and can access JavaScript object.

Top comments (1)

Collapse
 
Sloan, the sloth mascot
Comment deleted