Understand JSON Format and File Syntax

What JSON format is, what it looks like, its strict syntax rules, how it works in JavaScript, and what formatting and validation tools change in your data.

JSON (JavaScript Object Notation) is a plain-text format for representing structured data: objects, lists, strings, numbers, true/false and null. Programs use it to store data and pass it between each other, and people can still read it. This review covers what JSON looks like, what its syntax requires, how it relates to JavaScript, and what formatters and validators actually change when you run JSON through them.

Short answer: when JSON is the right choice

Use JSON when software needs to read the data, such as API requests and responses, configuration that a program loads, or data exchanged between systems written in different languages. Its main benefit is that it is simple, widely supported, and readable by both machines and people. The main tradeoff is strictness. JSON does not allow comments, has a small set of value types (no native dates or binary data), and fails on minor slips like a trailing comma. Plain text is better when the content is meant for people as prose, notes or messages. It is also better for hand-edited files that need comments. Formats that allow comments exist, but they are not standard JSON, and strict parsers will reject them.

What JSON looks like

JSON is built from two structures. An object is a set of name/value pairs inside curly braces, and an array is an ordered list of values inside square brackets. The two can be nested in each other to any depth. Here is a small illustrative example:

{
  "name": "Example Widget",
  "inStock": true,
  "tags": ["tools", "json"],
  "dimensions": { "width": 12.5, "height": 4 },
  "discontinued": null
}
  • A JSON value must be one of these types:
  • String: text in double quotes, such as "json"
  • Number: decimal notation with optional fraction and exponent, such as 4, 12.5 or 1e3
  • Object: name/value pairs in curly braces
  • Array: an ordered list of values in square brackets
  • Boolean: true or false
  • Null: null

How JSON is formatted: the syntax rules that trip people up

  • Object keys must be strings in double quotes. Unquoted keys are not allowed.
  • Strings use double quotes only. Single quotes are invalid.
  • No trailing comma is allowed after the last item in an object or array.
  • Comments are not part of JSON.
  • undefined, NaN, Infinity, functions and dates are not JSON values. Dates are usually stored as strings.
  • Numbers cannot have leading zeros (except 0 itself), a leading plus sign, or hexadecimal notation.
  • Only four characters count as whitespace between tokens: space, tab, line feed and carriage return.
  • Inside strings, double quotes, backslashes and control characters must be escaped, for example " for a quote, \ for a backslash, \n for a line break, or \uXXXX for a character code.

The first snippet below breaks four rules: single quotes, an unquoted key, a comment and a trailing comma. The second is the valid equivalent.

{
  'name': 'Widget',  // comment
  count: 3,
}
{
  "name": "Widget",
  "count": 3
}

What format JSON is, and what a JSON file is

JSON is a text-based, language-independent data format. It is standardized by ECMA-404 and IETF RFC 8259. A JSON file is an ordinary plain-text file, usually with the .json extension, and any text editor can open it. When JSON is served over the web, its registered media type is application/json. RFC 8259 requires UTF-8 encoding for JSON exchanged between systems that are not part of a closed ecosystem. Under the current specifications, the top level of a JSON document can be any value. An older specification required it to be an object or array, so some older tools may still expect that.

What JSON does and why people use it

JSON serializes data. It turns in-memory structures like objects, dictionaries and lists into text that can be saved or sent, and then turns that text back into equivalent structures on the other side. Typical uses include web API payloads, configuration files, data exports and structured logs. People choose it because nearly every programming language has a JSON library, because its objects and arrays map directly onto common data structures, and because the text stays readable. It has limits. It is more verbose than binary formats. It has no built-in way to declare which fields are required, so that needs a separate schema such as JSON Schema. And it cannot carry comments.

JSON in JavaScript

JSON's syntax comes from JavaScript object literals, but it is stricter, so not every JavaScript object literal is valid JSON. JavaScript has a built-in JSON object with two main methods. JSON.stringify converts a value to JSON text, and JSON.parse converts JSON text back into a value.

const data = { name: "Widget", count: 3 };
const text = JSON.stringify(data);          // '{"name":"Widget","count":3}'
const pretty = JSON.stringify(data, null, 2); // indented with 2 spaces
const back = JSON.parse(text);              // new object with the same values
  • Documented conversion behavior worth knowing:
  • Object properties whose value is undefined, a function or a symbol are left out. In arrays, those values become null.
  • NaN and Infinity become null.
  • Date objects become ISO 8601 strings. JSON.parse returns them as strings, not Date objects.
  • BigInt values make JSON.stringify throw a TypeError.
  • Integers larger than Number.MAX_SAFE_INTEGER (2^53 − 1) can lose precision when parsed into JavaScript numbers.
  • JSON.parse throws a SyntaxError on invalid input.

What formatting and validation tools actually change

Pretty-printing (also called beautifying) adds indentation and line breaks. Minifying removes them. Both change only the whitespace between tokens, so the parsed data stays identical. Whitespace inside a string value is part of the data, and a correct formatter leaves it alone. The two snippets below hold the same data, and the space in "a b" is preserved in both.

{"id":7,"label":"a b","items":[1,2]}
{
  "id": 7,
  "label": "a b",
  "items": [
    1,
    2
  ]
}

Some changes happen only on screen. Syntax highlighting, collapsible tree views and color themes in an editor or viewer change how JSON is displayed, not the characters stored in the file. Other operations do change the stored text. Check those before you rely on the output:

Operation | What changes | Is the data preserved?
Pretty-print | Whitespace between tokens | Yes
Minify | Whitespace between tokens | Yes
Syntax highlighting or tree view | Display only. The file is unchanged | Yes
Sort keys | Order of object members | Values are kept. Consumers or diffs that depend on order may behave differently
Escape non-ASCII | Characters such as é written as \u00e9 | Yes, but harder to read and search
Parse and re-serialize | Number notation (1.0 may become 1), duplicate keys, possibly large-number precision | Not guaranteed
Auto-repair of invalid input | Characters added or removed to make it parse | Depends on the guess. Review the result

Duplicate keys deserve special care. The specification says object names should be unique but does not define what parsers do when they are not. JavaScript's JSON.parse keeps the last value, and other parsers may behave differently. So a tool that parses and rewrites your JSON can silently drop one of the duplicates.

A JSON validator checks syntax, meaning whether the text parses as JSON. It does not check whether the data has the fields, types or values your application expects. That is schema validation, which is a separate step. Lenient tools that accept comments or trailing commas are not confirming valid JSON, and strict parsers may still reject the same input.

Will JSON stay readable and usable after copying or sharing?

Because JSON is plain text, copying and pasting it usually works, but some destinations can alter it. Editors or apps that apply typographic substitution may turn straight quotes into curly quotes, which makes JSON invalid. Rich-text environments may insert non-breaking spaces, which are not valid JSON whitespace outside strings. A hard line break inserted into a string value also breaks the JSON, because literal line breaks are not allowed inside strings. These effects depend on the destination and its settings, and one clean paste does not show that every environment behaves the same way. For important data, share JSON in a code block or as a file attachment, and validate it after pasting.

For readability and accessibility, pretty-printed JSON is generally easier to work with than minified JSON. Each value sits on its own line, which helps with line-by-line reading, diffing in version control and editing. A single long minified line is hard to scan visually and may be harder to navigate with assistive technology. This review has no tested evidence on specific screen readers or magnifiers, so check with the tools your audience actually uses. Escaping non-ASCII characters as \uXXXX sequences keeps the data correct, but a text search for the original characters will not find them. Raw JSON is also not a substitute for readable content. If people who do not work with code need the information, give them a plain-language summary or a table alongside the JSON.

Evidence and gaps

The syntax and file-format details here follow the published JSON specifications. The JavaScript behavior follows documented JSON.stringify and JSON.parse behavior. No specific formatting or validation tools were tested for this review, so it makes no claims about particular products' features, accuracy or data handling. If you paste sensitive data into an online formatter, check that tool's documented privacy and retention practices first. A tool's appearance or marketing tells you nothing reliable about how it handles your data.