TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

JavaScript JSON

JavaScript JSON Object Methods with examples on javascript json, stringify() method, parse() method, javascript tutorial, features, introduction, examples, variables, javascript array, javascript map, javascript string etc.

<< Back to JAVASCRIPT

JavaScript JSON

The 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

  • It generates and stores the data from user input.
  • It can transport the data from the server to client, client to server, and server to server.
  • It can also build and verifying the data.

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.

Methods Description
JSON.parse() This method takes a JSON string and transforms it into a JavaScript object.
JSON.stringify() This method converts a JavaScript value (JSON object) to a JSON string representation.

JavaScript JSON Example

Let'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>
Test it Now

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




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf