DEV Community

Cover image for learn JSON from head to toe
Sahil Saif
Sahil Saif

Posted on

learn JSON from head to toe

what is JSON ?

• JSON - JavaScript Object Notation

• JSON is a lightweight format for storing and transporting data.

• JSON is often used when data is sent from a server to web page

• JSON is language independent

The JSON format is almost identical to JavaScript objects.

• In json keys MUST be in strings, written with double quotes

• In JavaScript object, keys can be strings, numbers, or identifier names

json

In JSON, values must be one of the following data types:

  • string
  • number
  • object (JSON object)
  • array
  • boolean
  • null

In javaScript object , valuse must be one of the following data types:

  • string
  • number
  • object (JSON object)
  • array
  • boolean
  • null
  • function
  • date
  • undefined js object

🚥JSON.stringify( )

When sending data to a web server, the data has to be a string.

So thats why while before sending data we need to Convert it from a JavaScript object to a JSON

To make this happen we need JSON.stringify( ).
stringify

🚥JSON.parse( )

Likewise while we receiving data from a web server, the data is always a string.

So we need to Parse the data into javascript object to use the data in out applications.

And for this action we need to use JSON.parse()
parse


That's it for now , if you have any doubt let me know on comments and let's connected on Twitter

Top comments (0)