2 min read

JavaScript JSON

JavaScript Object Notation is a format for structuring data.A common use of JSON is to read data from a web server, and display the data in a web page.
JavaScript JSON

JSON is a format for storing and transporting data.JSON is often used when data is sent from a server to a web page.

JSON or JavaScript Object Notation is a format for structuring data.JSON is a lightweight data interchange format.JSON is language independent.JSON is "self-describing" and easy to understand.

Example

{
"employees":[
 {"firstName":"John", "lastName":"Doe"},
 {"firstName":"Anna", "lastName":"Smith"},
 {"firstName":"Peter", "lastName":"Jones"}
]
}

JSON Syntax Rules

  • Data is in name/value pairs.   e.g-->"firstName":"John"
  • Data is separated by commas.  e.g-->{"firstName":"John", "lastName":"Doe"}
  • Curly braces hold objects.  e.g-->{"firstName":"John", "lastName":"Doe"}
  • Square brackets hold arrays. e.g-->"employees":[{"firstName":"John", "lastName":"Doe"},{"firstName":"Anna", "lastName":"Smith"},]

Note: Use the JavaScript built-in function JSON.parse() to convert the string into a JavaScript object: var obj = JSON.parse(text);where text should be string object.

Use the JavaScript built-in function JSON.stringify() to Convert a JavaScript object into a string.It is also possible to stringify JavaScript arrays:

var obj = { name: "John", age: 30, city: "New York" };

JSON.stringify(obj);//'{ name: "John", age: 30, city: "New York" }'

https://miro.medium.com/max/1280/1*6W3AKTS7xAXFvpX-Q-uH5Q.jpeg
JavaScript JSON
https://www.w3schools.com/js/js_json.asp

#JavaScript #JSON #Parse() #Stringify() #Probyto #ProbytoAI

Subscribe and follow us for latest news in Data Science and Machine learning and stay updated!

Facebook: https://facebook.com/probyto
Twitter: https://twitter.com/probyto
LinkedIn: https://linkedin.com/company/probyto
Instagram: https://instagram.com/probyto