JSON (JavaScript Object Notation) is a plain-text format for structured data. It stores information as name-value pairs and lists, in a way that is easy for people to read and for software to process. The IETF standard for JSON, RFC 8259, calls it a lightweight, text-based, language-independent data interchange format.
What does JSON look like?
Here is a lead record, as a form tool might send it to a CRM:
{
"firstName": "Anna",
"lastName": "de Vries",
"company": "Example Ltd",
"consentToEmail": true,
"interests": ["pricing", "integrations"],
"employees": null
}
JSON has six kinds of values:
- Strings, in double quotes:
"Anna" - Numbers:
42or3.5 - Booleans:
trueorfalse - Null, for an empty value
- Objects, a set of name-value pairs in curly braces
- Arrays, an ordered list in square brackets
Objects and arrays can sit inside each other, so JSON can describe complex data, such as a customer with several orders.
Where does JSON come from?
Douglas Crockford specified and popularised JSON in the early 2000s, based on JavaScript's object syntax. It is now an official standard: ECMA-404, ISO/IEC 21778 and RFC 8259. Files use the .json extension and the media type application/json. JSON sent between systems should be encoded in UTF-8.
What is JSON used for?
- APIs. When one app asks another for data, the answer usually comes back as JSON. See API and REST API.
- Webhooks and integrations. A new sign-up, a closed deal or a postback from an affiliate network is often sent as a JSON message.
- Structured data for SEO. Google supports three formats for structured data and recommends JSON-LD, which is based on JSON, where your site allows it.
- Settings files. Many tools store their configuration in
.jsonfiles.
In JavaScript, JSON.parse() turns a JSON string into an object, and JSON.stringify() turns an object into a JSON string.
JSON vs XML
| JSON | XML | |
|---|---|---|
| Size | Short | Longer, because of opening and closing tags |
| Structure | Objects and arrays | Elements and attributes |
| Comments | Not allowed | Allowed |
| Validation | JSON Schema | XML Schema, with strong typing |
| Typical use | APIs, web apps, settings | Documents, sitemaps, many enterprise and older systems |
JSON is usually the easier choice for new APIs. XML is still common where documents, strict schemas or older systems are involved.
Common JSON mistakes
- Using single quotes instead of double quotes.
- Leaving a trailing comma after the last item.
- Adding comments, which JSON doesn't allow.
- Pasting text with curly "smart" quotes from a word processor.
A JSON validator will catch these before they break an integration.
Related terms
Frequently asked questions
What is JSON used for in marketing?
Most marketing and sales tools exchange data through APIs and webhooks, and those messages are usually JSON, for example a new lead sent from a form tool to a CRM. Websites also use JSON-LD, a JSON-based format, to add structured data that helps search engines understand a page.
Is JSON better than XML?
Neither is better for everything. JSON is shorter and maps directly to objects and lists in code, which suits APIs. XML supports attributes, comments and strict schemas, which suits documents and some enterprise systems. Many older systems and sitemaps still use XML.
Can JSON contain comments?
No. Standard JSON does not allow comments, trailing commas or single-quoted strings. Property names and strings must use double quotes. A single misplaced comma makes the whole file invalid, so use a validator when editing JSON by hand.