Online JSON Formatter

Full screen
1
X

Tool Introduction

JSON is a data interchange format.

Before JSON, people used XML to communicate data.

Because of its simplicity, JSON quickly took the Web world by storm and became an ECMA standard.

Almost all programming languages have libraries for parsing JSON. In JavaScript, we can use JSON directly because JavaScript has built-in JSON parsing.

In order to process JSON data conveniently, JSON provides json.js package, download address: http://lib.sinaapp.com/js/json2/json2.js

In the data transmission process, 

JSON is transmitted in the form of text, that is, strings, while JS operates JSON objects. Therefore, the conversion between JSON objects and JSON strings is the key.

E.g:

JSON string:

var str1 = '{ "name": "cxh", "sex": "man" }';

JSON object:

var str2 = { "name": "cxh", "sex": "man" };


Convert JSON string to JSON object

var obj = eval('(' + str + ')');

or

var obj = str.parseJSON(); 

or

var obj = JSON.parse(str); 

Then, it can be read like this:

Alert(obj.name);Alert(obj.sex);


Convert JSON object to JSON string

E.g:

var last=obj.toJSONString(); 

or

var last=JSON.stringify(obj); 

alert(last);