C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
JavaScript JSONThe JavaScript JSON is an acronym of JavaScript Object Notation. It provides a format for storing and transporting data. It is a lightweight human readable collection of data that can be accessed in a logical manner. Points to remember
JSON Syntax
1. While working with .json file, the syntax will be like:
{
"First_Name" : "value";
"Last_Name": "value ";
}
2. While working with JSON object in .js or .html file, the syntax will be like:
var varName ={
"First_Name" : "value";
"Last_Name": "value ";
}
JavaScript JSON Methods
Let's see the list of JavaScript JSON method with their description.
JavaScript JSON ExampleLet's see an example to convert string in JSON format using parse() and stringify() method.
<script>
//JavaScript to illustrate JSON.parse() method.
var j = '{"Name":"Krishna","Email": "XYZ", "CN": "12345"}';
var data = JSON.parse(j);
document.write("Convert string in JSON format using parse() method<br>");
document.write(data.Email); //expected output: XYZ
//JavaScript to illustrate JSON.stringify() method.
var j = {Name:"Krishna",
Email: "XYZ", CN : 12345};
var data = JSON.stringify(j);
document.write("<br>Convert string in JSON format using stringify() method<br>");
document.write(data); //expected output: {"Name":"Krishna","Email":"XYZ","CN":12345}
</script>
Output: Convert string in JSON format using parse() method
XYZ
Convert string in JSON format using stringify() method
{"Name":"Krishna","Email":"XYZ","CN":12345}
Next TopicJavaScript JSON
|