TheDeveloperBlog.com

Home | Contact Us

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

JavaScript JSON parse() Method

JavaScript JSON parse() Method 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.parse() method

The JavaScript JSON.parse() takes a JSON string and transforms it into a JavaScript object.

Syntax

JSON.parse(text[, reviver])

Parameters

text: The string to parse as JSON.

reviver: It is Optional. It prescribes how the value originally produced by parsing is transformed, before being returned.

Return value

An object corresponding to the given JSON text.

Browser Support

Chrome Yes
Safari 4
Firefox 3.5
Opera 10.5

JavaScript JSON.parse() method Examples

Example 1

Let's see a simple example to parse an object.

<script>
//JavaScript to illustrate JSON.parse() method.
var json = '{ "firstName":"ASHU", "lastName":"BHATI", "studentCode":7 }';
var student = JSON.parse(json);
// expected output: ASHU BHATI
document.write(student.firstName + " " + student.lastName); 
</script>
Test it Now

Output:

ASHU BHATI

Example 2

Let's see an example to parse a particular attribute.

<script>
//JavaScript to illustrate JSON.parse() method.
var json = '{ "firstName":"ASHU", "lastName":"BHATI", "studentCode":7 }';
var student = JSON.parse(json);
// expected output: 7
document.write(student.studentCode); 
</script>
Test it Now

Output:

7

Example 3

Let's see an example to parse an array of attributes.

<script>
//JavaScript to illustrate JSON.parse() method.
var j = '["C++","JavaScript","Python","HTML"]';
var data = JSON.parse(j);
document.write(data);
 //expected output: C++,JavaScript,Python,HTML
</script>
Test it Now

Output:

C++, JavaScript, Python, HTML
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