Skip to content
Buy me a coffee
Formatters

JSON Formatter & Beautifier

Formats a JSON string or file with the chosen indentation level, creating a colour-highlighted, collapsible tree so you can clearly identify objects, arrays and members.

0 characters · 0 lines
Option 2: Or upload your JSON file
Ctrl + Enter

JSON Explained

What is JSON?

JSON stands for JavaScript Object Notation and is pronounced "Jason". It is a human-readable and compact text format used to represent structured data and to exchange it between systems. It is defined by RFC 8259 and ECMA-404.

Why use JSON?

  • It is human readable… if it is properly formatted!
  • It is compact because it does not use a full markup structure, unlike XML.
  • It is easy to parse in every programming language and a huge number of libraries are available.
  • The data structure (objects, arrays, values) maps naturally to the types of most languages.

JSON format rules

  • Objects are enclosed in curly brackets { }; an empty object is {}.
  • Arrays are enclosed in square brackets [ ]; an empty array is [].
  • A member is a key-value pair. The key must be a string in double quotes and should be unique within an object.
  • String values must be enclosed in double quotes. "Offensive" characters (", \, control characters) must be escaped with a backslash.
  • Booleans are the literals true and false, in lower case. Null is the literal null.
  • Numbers use double-precision floating point format; scientific notation is supported. Numbers must not have leading zeroes and cannot be NaN or Infinity.
  • Dates and other types are not supported natively and should be represented as strings (ISO 8601 is recommended).
  • Each member of an object or item of an array must be followed by a comma unless it is the last one (no trailing commas).
  • The common extension for JSON files is .json and the MIME type is application/json.
{
   "anObject": {
      "numericProperty": -122,
      "stringProperty": "An offensive \" is problematic",
      "nullProperty": null,
      "booleanProperty": true,
      "dateProperty": "2011-09-23"
   },
   "arrayOfObjects": [ { "item": 1 }, { "item": 2 }, { "item": 3 } ],
   "arrayOfIntegers": [ 1, 2, 3, 4, 5 ]
}

JSON in JavaScript

Never parse JSON with eval(): it executes arbitrary code and opens the door to security issues. Use JSON.parse() instead, and JSON.stringify() to produce JSON:

// A valid json string
const someJsonString = '{"someProperty":"someValue"}';
const jsonObject = JSON.parse(someJsonString);
console.log(jsonObject.someProperty);     // "someValue"

const text = JSON.stringify({ a: 1, b: [1, 2] }, null, 3);   // pretty printed with 3 spaces