Data Formats

JSON Format Explained: Syntax, Data Types, and Structure

A plain-language definition of JSON format, with syntax rules, data types, valid vs invalid JSON, common mistakes, and how JSON compares to XML and YAML.

HandyUtils January 10, 2026 14 min read

JSON is the data format that powers modern web APIs, configuration files, and countless developer tools. If you have ever inspected a network request or edited a config file, you have already read JSON. Here is a clear, practical guide to what it is and how it works.

What Is JSON?

JSON (JavaScript Object Notation) is a lightweight, text-based data format for storing and exchanging structured data as human-readable key–value pairs. It is language-independent, so almost every programming language can read and write it. A minimal JSON document looks like this:

{ "name": "Ada", "age": 36 }

That single object has two fields: name (a string) and age (a number). From this basic shape—keys paired with values—JSON scales up to describe anything from a user profile to an entire application configuration.

JSON was created by Douglas Crockford in the early 2000s as a simpler alternative to XML. Its syntax mirrors JavaScript object literals, which made it a natural fit for the web, but today it is the default data format for REST APIs, NoSQL databases, and config files across every language and platform.

A more complete example:

{
  "name": "Ada",
  "age": 36,
  "isActive": true,
  "roles": ["admin", "editor"],
  "address": {
    "city": "London",
    "zip": "EC1A"
  }
}

JSON Syntax Rules

JSON has strict, unambiguous syntax—stricter than JavaScript itself.

1. Data is written as key–value pairs

"key": "value"

2. Keys must be strings in double quotes

{"name": "Ada"}     ✓ Valid
{name: "Ada"}       ✗ Invalid (unquoted key)
{'name': 'Ada'}     ✗ Invalid (single quotes)

3. Values must be a valid JSON type

A string, number, boolean, null, array, or object—nothing else.

4. Items are separated by commas, with no trailing comma

{"a": 1, "b": 2,}     ✗ Invalid
{"a": 1, "b": 2}      ✓ Valid

5. No comments

JSON does not support comments. It is a data format, not a document format.

JSON Data Types

JSON supports exactly six data types. Three are primitives (string, number, boolean), one is the empty value (null), and two are containers (object, array).

String

Text in double quotes. Special characters are escaped with a backslash:

{
  "simple": "Hello",
  "quoted": "She said \"Hi\"",
  "multiline": "Line 1\nLine 2",
  "unicode": "Smiley: \u263A"
}

Escape sequences: \" \\ \/ \b \f \n \r \t \uXXXX.

Number

No quotes. Integers, decimals, and scientific notation are all valid:

{ "integer": 42, "negative": -17, "decimal": 3.14, "scientific": 1.23e10 }

There is no hex (0xFF), octal (077), or leading zeros, and NaN/Infinity are not valid JSON.

Boolean

Lowercase true or false only:

{ "active": true, "deleted": false }

Null

Represents the intentional absence of a value:

{ "middleName": null }

Object

An unordered collection of key–value pairs in curly braces:

{ "name": "Bob", "age": 25 }

Array

An ordered list of values in square brackets:

{ "numbers": [1, 2, 3], "mixed": [1, "two", true, null] }

JSON Structure: Objects and Arrays

Every JSON document is built from two container types, and knowing when to use each is the key to well-structured data.

Use an object {} for named properties, where each value has a meaningful key:

{ "name": "Product", "price": 29.99, "inStock": true }

Use an array [] for an ordered collection of similar items:

{ "tags": ["electronics", "sale", "featured"] }

The two combine to form the most common shape in real APIs—an array of objects, which maps neatly onto rows and columns:

{
  "users": [
    { "id": 1, "name": "Alice" },
    { "id": 2, "name": "Bob" }
  ]
}

Because objects and arrays can hold other objects and arrays, JSON can describe deeply nested, hierarchical data:

{
  "company": "Tech Corp",
  "departments": [
    {
      "name": "Engineering",
      "employees": [
        { "name": "Alice", "skills": ["Python", "JavaScript"] }
      ]
    }
  ]
}

This nesting is what CSV cannot do—see CSV Files Explained for how flat, tabular data compares.

Valid vs Invalid JSON

Most JSON errors come from treating it like JavaScript or a relaxed config syntax. These are the mistakes a parser will reject:

Mistake Invalid Valid
Single quotes {'name': 'Ada'} {"name": "Ada"}
Unquoted keys {name: "Ada"} {"name": "Ada"}
Trailing comma {"a": 1,} {"a": 1}
Comments {"a": 1} // note {"a": 1}
Unescaped backslash {"path": "C:\Users"} {"path": "C:\\Users"}
Raw newline in string a literal line break {"text": "a\nb"}

A few rules worth calling out:

  • Trailing commas are valid in modern JavaScript but never in JSON.
  • Single quotes are never allowed—strings and keys both require double quotes.
  • Comments (// or /* */) are not part of JSON; if you need them, use YAML or a JSONC variant.

When in doubt, paste your data into a validator. Our JSON Formatter and Validator pinpoints the exact line and character where JSON breaks.

JSON vs XML vs YAML

JSON is one of three data formats you will meet constantly. Here is how they compare:

Feature JSON XML YAML
Syntax {"k": "v"} <k>v</k> k: v
Verbosity Compact Verbose Minimal
Data types Yes All text Yes
Arrays Native Conventions Native
Comments No Yes Yes
Whitespace significant No No Yes
Best for APIs, data Documents Config files

JSON won for APIs because it is compact, fast to parse, and natively supported in browsers. XML remains useful for documents that need attributes, namespaces, and comments. YAML is a superset of JSON that trades braces for indentation, which makes it popular for human-edited configuration—see JSON vs YAML for a deeper comparison.

Working with JSON in Code

Every major language has built-in JSON support.

JavaScript:

const obj = JSON.parse('{"name": "Ada"}');   // string → object
const json = JSON.stringify(obj, null, 2);    // object → pretty string

Python:

import json
obj = json.loads('{"name": "Ada"}')   # string → dict
text = json.dumps(obj, indent=2)       # dict → JSON string

Always wrap parsing of untrusted input in error handling—invalid JSON throws:

try {
  const data = JSON.parse(userInput);
} catch (e) {
  console.error("Invalid JSON:", e.message);
}

Converting and Formatting JSON

JSON rarely lives alone. You will often need to reshape it into another format or clean it up:

For transmission, JSON is usually minified ({"name":"Ada","age":36}) to save bytes, then pretty-printed with indentation when you need to read it.

Summary

  • JSON is a lightweight, text-based format for structured data, built from key–value pairs.
  • It supports six data types: string, number, boolean, null, object, and array.
  • Syntax is strict: double quotes only, no trailing commas, no comments.
  • Objects hold named properties; arrays hold ordered lists; together they nest to describe any data.
  • It is language-independent and the default format for web APIs and configuration.

Ready to work with JSON? Clean up and check your data with the JSON Formatter and Validator, then reshape it with JSON to CSV, CSV to JSON, JSON to YAML, or XML to JSON.

Frequently Asked Questions

If a parser has rejected your file, see Common JSON Errors and How to Fix Them for the exact messages and their fixes, or paste the text into the JSON Formatter and Validator to see where it breaks.

What is JSON format?

JSON format is a text-based way of writing structured data as key–value pairs inside objects {} and arrays []. A value can be a string, number, boolean, null, object, or array. Because it is plain text, JSON can be read by humans and parsed by nearly every programming language, which is why it is the standard for web APIs.

What is JSON notation?

"JSON notation" refers to the syntax JSON uses to write data: keys and string values in double quotes, colons between keys and values, commas between items, curly braces for objects, and square brackets for arrays. The name itself—JavaScript Object Notation—describes this notation, which is modeled on JavaScript object literals.

What is valid JSON?

Valid JSON is text that follows the grammar in RFC 8259 (also published as ECMA-404): exactly one value, where a value is an object, an array, a string, a number, true, false or null. Objects use curly braces with double-quoted string keys and colons, arrays use square brackets, and items are separated by single commas with none trailing. Anything outside that grammar—comments, single quotes, undefined, a trailing comma—makes the whole document invalid, and most parsers reject the entire input rather than just the offending part.

What are the JSON syntax rules?

Data is written as "key": value pairs; keys must be strings in double quotes; values must be one of the six JSON types; objects go in {} and arrays in []; items are separated by commas with no trailing comma; strings use double quotes and escape ", \ and control characters with a backslash; numbers are plain decimal with no leading zeros, hex, NaN or Infinity; the literals true, false and null are lowercase; comments are not allowed; and whitespace between tokens is ignored. Everything is case-sensitive.

What is the difference between

Curly braces {} create an object: an unordered set of named key–value pairs, used when each value has a distinct label such as "name" or "price". Square brackets [] create an array: an ordered list of values accessed by position, used for collections of similar items. {} on its own is an empty object and [] is an empty array, and the two are frequently combined as an array of objects.

Is an array valid JSON?

Yes. Since RFC 7159 in 2014, any JSON value may appear at the top level, so [1, 2, 3] is a complete, valid JSON document, and so are "hello" and 42. The original 2006 specification (RFC 4627) required the top level to be an object or an array, and some older validators and APIs still expect an object, so if a tool complains, wrap the array in an object such as {"items": [1, 2, 3]}.

What data types does JSON support?

JSON supports six types: string (double-quoted text), number (integer or decimal), boolean (true/false), null, object (key–value pairs), and array (ordered list). There is no separate date, integer-vs-float, or binary type—dates are usually stored as ISO 8601 strings.

What number types does JSON support, and does it allow scientific notation?

JSON has a single number type: an optional minus sign, an integer part with no leading zeros, an optional fraction, and an optional exponent written with e or E. So 42, -3.5, 1e10 and 6.02E-23 are all valid, while +1, 01, .5, 0x1F, NaN and Infinity are not. The standard does not fix precision; JavaScript parses every number as a 64-bit float, so integers above 253 (9,007,199,254,740,991) lose precision, which is why large IDs are usually sent as strings.

Is JSON a string?

JSON is a text format, so a JSON document is always a string while it sits in a file, travels over a network, or waits in a variable to be parsed. JSON.stringify() turns an in-memory object into that string and JSON.parse() turns it back into live objects and arrays. Separately, "string" is also one of the six JSON value types, meaning double-quoted text such as "Ada".

Is JSON the same as a JavaScript object?

No. JSON is a text format inspired by JavaScript object syntax, but it is stricter: keys must be double-quoted strings, values are limited to the six JSON types, and functions, undefined, comments, and trailing commas are not allowed. A JavaScript object lives in memory; JSON is a string you can save to a file or send over a network.

Is JSON structured or unstructured data?

JSON is usually described as semi-structured data. It has explicit structure—nested objects, arrays, and named keys—but no fixed schema, so one object can have different keys from the next. That puts it between rigidly structured relational tables and unstructured content such as free text or images. If you need strict rules, JSON Schema can validate a document's shape.

Is JSON human readable?

Yes. JSON is plain text with descriptive keys, so a pretty-printed document is easy to scan. Minified JSON, with all whitespace removed, is much harder to read; paste it into the JSON Formatter to indent it and view it as a collapsible tree.

Are there JSON naming conventions (camelCase vs snake_case)?

The specification does not mandate one. camelCase (firstName) is the most common choice in JavaScript-centred APIs and is what Google's JSON style guide recommends; snake_case (first_name) is common in Python and Ruby ecosystems and in APIs such as Stripe's. Pick one convention per API, apply it consistently, avoid spaces and hyphens in keys because they are awkward to use as identifiers, and remember that keys are case-sensitive.

Can JSON have comments?

No. JSON has no comment syntax, and a // or /* */ comment causes a parse error in strict parsers such as JSON.parse and .NET's System.Text.Json with default settings. Some configuration files use a relaxed dialect such as JSONC or JSON5 (VS Code's settings.json and tsconfig.json, for example), and Newtonsoft's Json.NET skips comments, but that is a property of those tools, not of JSON. If you need documentation inside a config file, use a "_comment" key (which becomes data) or switch to YAML.

What are the limitations of JSON?

JSON has no comments, no date or time type (ISO 8601 strings are the convention), no binary type (bytes are usually Base64-encoded strings), and a single number type with no guaranteed precision. It cannot express references or cycles, so shared or circular structures must be flattened. Duplicate keys have undefined behaviour, there is no built-in schema (JSON Schema is a separate specification), and the strict syntax—no trailing commas, no single quotes—makes hand-editing error-prone.

What does "Expected a JSON object, array or literal" mean?

This message comes from the JSON language service used by Visual Studio Code and by editors built on the same components, such as GitHub's web editor. It means the file is being treated as JSON but the first non-whitespace content is not a valid JSON value: the file is empty, starts with a comment or stray text, or is not JSON at all and has been mis-detected. Make sure the document begins with {, [, a quoted string, a number, or true/false/null, or change the editor's language mode. See Common JSON Errors for the equivalent errors in browsers, Python and .NET.

What is a JSON payload?

A JSON payload is the JSON body of an HTTP request or response—the actual data being carried, as opposed to headers and other metadata. A POST request might send the payload {"email": "ada@example.com"} with a Content-Type: application/json header, and the API replies with a JSON payload of its own. To inspect a payload you have captured, paste it into the JSON Formatter.

What is the .json file format?

A .json file is a plain-text file, normally UTF-8 encoded without a byte order mark, that contains exactly one JSON document. Its MIME type is application/json. It opens in any text editor and is used for configuration (package.json, tsconfig.json, appsettings.json), API exports, and data interchange. Because it is just text, you can format it, convert it to CSV or YAML, or validate it with the tools on this site.

Related Topics
json json format what is json json syntax json structure json notation json data types valid json json syntax rules json payload json file format
Share this article

Continue Reading

Data Formats
JSON vs YAML (vs XML): Choosing the Right Configuration Format

A practical comparison of JSON, YAML and XML: syntax differences, when to use each for configuration and data exchange, and how to convert between them.

Development
Common JSON Errors and How to Fix Them

How to fix JSON parse errors such as 'Expected a JSON object, array or literal', 'Unexpected token' and 'Expecting value': trailing commas, quotes, comments, BOMs and more.