JSON Validator, Formatter, Minifier and Editor
What is JSON?
Structure of JSON Object:A JSON can be:
JSON Example:The following example shows a JSON representation of a person object.
{
"firstName": "John",
"lastName": "Snow",
"age": 25,
"children": [],
"spouse": null,
"address": {
"street": "7504 Taylor Drive",
"city": "New York City",
"state": "New York",
"postalCode": "11238"
},
"phoneNumbers": [
{
"type": "mobile",
"number": "212 555-3346"
},
{
"type": "fax",
"number": "646 555-4567"
}
]
}
In the above example,
JSON Syntax Rules:
JavaScript JSON built-in library:JavaScript JSON built-in library provides two functions to decode and encode JSON objects - JSON.parse()
and JSON.stringify().
1. JSON.stringify() returns a JSON string corresponding to a JavaScript object.
Output: {"fruit":"Apple", "types":["Small","Medium","Large"], "quantity":1000} 2. JSON.parse() is safe and fast method of decoding a JSON string as Javascript object.
Output: Apple, [Small,Medium,Large], 1000 We can also parse a JSON string into a JavaScript object by invoking the eval() function on the JSON
string wrapped by parenthesis. This works since JSON is derived from JavaScript. eval() is an evil
function, which should be avoided at all costs. This is because eval can execute any malicious scripts on
the user's machine with privileges of the caller. Moreover, malicious code can find the scope in which eval() was
invoked, which can make the website vulnerable to attacks. JSON.parse() is the safe and fast alternative of eval which safely fails on malicious code. JSON is
included in almost all modern browsers. For old versions of browsers, use external JavaScript library such as Douglas Crockford's json2.js.
Data Exchange with JSON:JSON is primarily used for transmission of serialized text between a browser and a server.
The official Media type for JSON is application/json. Programming Languages Support:Originally, JSON was intended to be a subset of the JavaScript languages but now almost all major programming languages supports JSON due to its language-independent data format. JSON's official website lists major JSON libraries available in various programming languages which can be used to parse and generate JSON. For instance, the most popular JSON libraries for Java are: GSON, JSON.simple, Jackson, and JSONP. Enter the URL to load JSON |
|
|||||