

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to convert a JSON string into a JavaScript object?
Javascript has provided JSON.parse() method to convert a JSON into an object. Once JSON is parsed we can able to access the elements in the JSON.
syntax
var obj = JSON.parse(JSON);
It takes a JSON and parses it into an object so as to access the elements in the provided JSON.
Example-1
In the following example, a JOSN is assigned to a variable and converted it into an object and later on displayed the values of the elements in the JSON as shown in the output.
<html> <body> <script> var json = '{"name": "Malinga", "age": 32, "country": "srilanka"}'; var obj = JSON.parse(json); document.write(obj.name + "</br>"); document.write(obj.age + "</br>"); document.write(obj.country); </script> </body> </html>
Output
Malinga 32 srilanka
Example-2
<html> <body> <script> var json = '{"company": "Tutorialspoint", "Product": "Tutorix", "city": "Hyderabad"}'; var obj = JSON.parse(json); document.write(obj.company+ "</br>"); document.write(obj.Product+ "</br>"); document.write(obj.city); </script> </body> </html>
Output
Tutorialspoint Tutorix Hyderabad
- Related Questions & Answers
- How to convert JSON data into a Python object?
- How to deserialize a JSON into Javascript object?
- How to convert a date object's content into json in JavaScript?
- How to transform JSON text into a JavaScript object?
- How can we convert a JSON string to a JSON object in Java?
- Strip quotes with JavaScript to convert into JSON object?
- How to turn a JSON object into a JavaScript array in JavaScript ?
- How to convert JSON text to JavaScript JSON object?
- How to convert JSON string into Lua table?
- How to convert a string to JavaScript object?
- How to convert a JavaScript date object to a string?
- Converting two arrays into a JSON object in JavaScript
- Convert JSON array into normal json in JavaScript
- How to convert a String into a Date object using JDBC API?
- Convert a string to hierarchical object - JavaScript
Advertisements