Thursday, August 31, 2017

JSON object to string

 
  •        A common use of JSON is to exchange data to/from a web server
  •       When sending data to a web server, the data has to be a string
  •       Convert a JavaScript object into a string with JSON.stringify()
Edit in plkr

 console.log("*** Convert JSON object to a string");
  var obj={
    firstName:"Prathap",
    lastName:"Kudupu"
  }
  console.log('\n obj', obj)
  console.log('Convert JSON object to string',JSON.stringify(obj));

Output

Note: The difference between string and object is that the property name is the object is not a string


No comments:

Post a Comment