What is JSON?
JSON is how programs hand data to each other across the web. Here is the syntax, the six types, how it differs from XML, and why it underpins every API and AI call.
What JSON is
JSON (JavaScript Object Notation) is a lightweight, text-based format for representing structured data, objects, lists, and the simple values inside them. It was derived from JavaScript’s object syntax but is now language-independent: every mainstream language can read and write it. When one program sends data to another, over an API, in a config file, in a log line, the data is very often JSON. It won because it is human-readable and maps almost one-to-one onto the data structures (objects/dicts and arrays/lists) that code already uses.
The syntax, at a glance
JSON is built from key/value pairs inside objects, and ordered lists inside arrays. Keys are always double-quoted strings; values are one of the six types below.
{
"name": "Ada Lovelace",
"born": 1815,
"active": true,
"fields": ["mathematics", "computing"],
"collaborator": { "name": "Charles Babbage" },
"spouse": null
} Two rules trip everyone up at least once: keys and string values use double quotes (never single), and there is no trailing comma after the last item. JSON also has no comments.
The six data types
| Type | Example | Notes |
|---|---|---|
| string | "hello" | Double quotes always |
| number | 42, 3.14 | One type, no int/float split |
| boolean | true, false | Lowercase |
| null | null | Explicit “no value” |
| array | [1, 2, 3] | Ordered list, any types |
| object | { } of pairs | Unordered key/value map |
Notably absent: no date type (dates travel as strings, usually ISO 8601 like
"2026-06-19") and no undefined. Anything richer is encoded on top of these six.
Parsing & serializing
JSON is a string until you parse it into a live object, and you serialize an object back into a string to send it. The two operations are mirror images, and look nearly identical across languages:
// JavaScript: text <-> object
const obj = JSON.parse(text); // string -> object
const text = JSON.stringify(obj); // object -> string
// Python: identical idea, different names
import json
obj = json.loads(text) # string -> dict
text = json.dumps(obj) # dict -> string Need a typed shape from a sample? The JSON → TypeScript tool turns any JSON into an interface; CSV → JSON and YAML → JSON convert the neighbors.
JSON vs XML
| JSON | XML | |
|---|---|---|
| Shape | Maps to objects/arrays | A document tree |
| Verbosity | Light | Heavier (open + close tags) |
| Attributes | None (keys only) | Yes (plus elements) |
| Comments | No | Yes |
| Schema | JSON Schema (optional) | XSD / DTD (mature) |
| Best for | APIs, config, data interchange | Documents, mixed content, RSS/Atom, SOAP |
For a full breakdown of the document side, see what XML is.
JSON & AI
Model APIs speak JSON: your request, the model’s response, and every tool call are JSON payloads. The big
reliability win is structured outputs, where you give the model a
schema and it is constrained to emit JSON that matches, so your code can JSON.parse the
answer instead of scraping it out of prose. Build one visually with the
Structured Output Builder.
Common mistakes
- Trailing comma after the last array/object item. Valid in JavaScript, invalid in JSON.
- Single quotes or unquoted keys. JSON requires double-quoted keys and strings.
- Comments. JSON has none; strip them (or use JSON5/JSONC, which are different formats).
- Sending a date or function as-is. Encode dates as strings; functions can’t be represented.
- Confusing the string with the object. Parse before you index into it, stringify before you send it.
FAQ
What does JSON stand for?
JavaScript Object Notation. It was derived from JavaScript's object syntax, but it is now a language-independent data format with parsers in essentially every programming language.
Is JSON the same as a JavaScript object?
No. JSON is a text format, a string. A JavaScript object is a live in-memory value. JSON's rules are also stricter: keys must be double-quoted strings, there are no trailing commas, no comments, and no functions or dates as values. You convert between them with JSON.parse and JSON.stringify.
What data types can JSON hold?
Six: string, number, boolean (true/false), null, array, and object. That is the whole list. There is no date type (dates are sent as strings), no integer-vs-float distinction (just number), and no undefined.
JSON vs XML, which should I use?
For most modern APIs and config, JSON: it is lighter, maps directly onto data structures in code, and is faster to parse. Reach for XML when you need its specific strengths, mixed content (markup inside text), attributes plus namespaces, or schema validation via XSD, as in many enterprise and document formats.
Why do I keep getting 'Unexpected token' errors?
Almost always a syntax slip JSON does not forgive: a trailing comma after the last item, single quotes instead of double quotes, unquoted keys, or a comment. JSON has no comments and no trailing commas, paste the text into a validator to find the exact position.
Does JSON preserve the order of object keys?
The JSON spec says objects are unordered, so you should not rely on key order for correctness. In practice most parsers (including JavaScript and Python 3.7+) do preserve insertion order, but treat that as a convenience, not a guarantee.
How does JSON relate to AI and LLMs?
JSON is the lingua franca of model APIs: requests, responses, and tool calls are JSON, and 'structured outputs' constrain a model to emit JSON matching a schema so your code can parse it reliably instead of scraping prose.
KB Cafe came up in the era when XML ran the web and JSON was the upstart, lighter alternative. JSON won the data-interchange layer; XML kept the document and feed layer. This is the modern reference for the format that now carries almost every API call, and every AI one.