Javascript - Reference JSON Reference

JSON stands for JavaScript Object Notation)

JSON is a format for storing and transporting data.

JavaScript Objects can be converted into JSON, and JSON can be converted back into JavaScript Objects.


var myObj = { "name":"John", "age":31, "city":"New York" };
var myJSON = JSON.stringify(myObj);
console.log( myJSON );


Valid Data Types

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

  • a string
  • a number
  • an object (JSON values. for nesting)
  • an array
  • a boolean
  • null

JSON values cannot be one of the following data types:

  • a function
  • a date
  • undefined


//Convert a string written in JSON format, into a JavaScript object.
var myJSON = '{ "name":"John", "age":31, "city":"New York" }';
var myObj = JSON.parse(myJSON);
console.log( );//from  ww w .  j  a va  2  s.  co m