What JSON is

JSON (JavaScript Object Notation) is a language-independent text format for representing structured data. A JSON document can be one value—an object, array, string, number, true, false, or null—and objects and arrays can contain nested values.[1]

For example, this object stores a person's name and a list of roles:

{
  "name": "Ada",
  "roles": ["admin", "reviewer"],
  "active": true
}

JSON is used widely for configuration and data exchange, including many HTTP APIs, but not every app or API uses it.[1] The format is independent of a particular programming language, even though its name refers to JavaScript.[1][2]

This guide explains the syntax, shows how to parse and validate data, and highlights the distinctions that prevent common bugs. Use the JSON Formatter to inspect a sample as you follow along.

The building blocks

JSON has six value types: four primitive types and two structured types.[1]

  • Objects — an unordered set of name-value pairs in curly braces: {"name": "NAB Tools"}. Each name is a string.[1]
  • Arrays — an ordered sequence of values in square brackets: ["dns-lookup", "ip-check"]. Values in an array do not have to share a type.[1]
  • Strings — double-quoted text: "hello world".[1]
  • Numbers — integers and decimals: 43, 3.14, -7.[1]
  • Booleans — true or false.[1]
  • null — an explicit empty value.[1]

An object may contain any JSON value, including another object or array. A top-level JSON value does not have to be an object; arrays and primitive values are valid JSON too.[1]

The rules that catch people out

JSON resembles JavaScript object syntax, but it is a separate, stricter data format. These are valid JSON rules:[1][2]

  • Double quotes only — keys and strings must use ", not single quotes.[2]
  • No trailing commas — {"a": 1,} is an error. The last item never has a comma.[2]
  • No comments — standard JSON has no comment syntax; JSON5 and JSONC are separate, non-standard variants.[2]
  • No undefined or functions — only the six types above exist; JavaScript-only values break parsers.[2]

Where JSON rules the world

JSON is commonly used for data exchange between applications written in different languages, but each application chooses its own formats and contracts.[1]

  • APIs — many HTTP APIs send and receive JSON; check the specific API's documentation rather than assuming it does.[1]
  • Configuration files — package.json and tsconfig.json are JSON files; some tools instead accept variants such as JSON5 or JSONC.[2]

Working with JSON in code

In JavaScript, JSON.parse() reads JSON text and returns the corresponding JavaScript value; JSON.stringify() serializes a JavaScript value to JSON text when that value is representable.[2] For example:

const text = '{"name":"Ada","active":true}';
const person = JSON.parse(text);
console.log(person.name); // "Ada"

const again = JSON.stringify(person);

Parsing checks JSON syntax, not whether the data meets your application's rules. For that, define and validate a data contract; JSON Schema is one option for expressing structural expectations.[3]

Use a formatter to check syntax, make nested data easier to inspect, or compact whitespace.[2] Pretty-printing changes presentation, not the represented values, assuming the input is valid JSON and the formatter preserves it.

Tip: Formatting helps you inspect syntax; it does not check required fields, allowed values, authorization, or whether the payload is safe to trust.

Read JSON as a data tree

Start at the outer value. An object uses braces and named members; an array uses brackets and ordered values. Each member has a string key and a value that can itself be an object or array.[1] For example, {"user":{"name":"Ada"},"roles":["admin","reviewer"]} is one object containing a nested object and an array.

JSON has six value types: object, array, string, number, boolean, and null.[1] It has no separate date, integer, decimal, or undefined type.[1][2] Applications decide what strings and numbers mean, so an ISO date such as "2026-11-16" is still a string. Although JSON's number grammar is not limited to a specific machine precision, some programming environments cannot represent every very large integer exactly; for identifiers that must remain exact, agree on a representation such as a string.[1]

Common errors and data contracts

Missing commas, single-quoted strings, trailing commas, unescaped control characters, comments, and unquoted keys are common reasons a parser rejects JSON.[1][2] Object names should be unique: when they are duplicated, implementations can disagree about which value applies.[1] For important payloads, document required fields, optional fields, allowed values, units, nullability, and version changes. A JSON Schema can express many structural expectations.[3]

When sending JSON over HTTP, follow the API's documented content type and validate untrusted input against both syntax and application requirements. Set appropriate size limits and handle parser errors without exposing sensitive payloads. Formatting makes a payload readable; it does not validate business rules, authenticate a sender, or remove secrets.

A practical debugging workflow

  1. Reduce the failing payload to the smallest example that still breaks.
  2. Format it to locate the structural error.
  3. Compare the shape with the producer's schema or API documentation.
  4. Check types, optional fields, encoding, and date/number assumptions.
  5. Test both a normal case and a missing, empty, null, or unexpectedly large value.

Use a JSON formatter for inspection and a converter when moving between formats, but keep production validation in the application that owns the data. If you convert JSON to a format with fewer data types or nesting, review the result for information that may not carry over.

Practical takeaway

JSON is straightforward once you recognize its six value types and the difference between syntax and an application's data contract. Parse and format it to inspect structure, then validate required fields, types, and allowed values in the system that uses it. Do not assume that valid JSON is automatically meaningful or safe.

FAQ

What does JSON stand for?

JavaScript Object Notation.[1] It is a language-independent text format for structured data, not a programming language.[1]

Is JSON a programming language?

No. JSON represents data; it does not define executable functions or computation.[1][2] Programs can parse JSON and then act on the resulting values.[2]

Can JSON contain comments?

No. Standard JSON has no comment syntax. Some tools support separate variants such as JSON5 or JSONC, but a standard JSON parser may reject their comments.[2]

What is the difference between JSON and a JavaScript object?

They look similar but are not interchangeable. JSON requires quoted string names, disallows trailing commas and comments, and has no undefined or function value; JavaScript object literals allow syntax that JSON does not.[2]

How do I check if my JSON is valid?

Paste it into the JSON Formatter to check syntax and inspect the formatted result. Syntax validation does not prove that the data meets an API or application's requirements.[3]

Sources

[1] https://www.rfc-editor.org/rfc/rfc8259.html — RFC 8259: The JavaScript Object Notation (JSON) Data Interchange Format [2] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON — JSON - JavaScript | MDN [3] https://json-schema.org/docs — JSON Schema documentation