Dashboard

What Is JSON? Read It, Fix It, and Ask AI for It

JSON is the text format apps use to pass data around. Learn to read it, fix the five errors that break it, and ask AI for output your code can parse.

Steve Jefferson
Steve Jefferson
Developer Advocate
20 October 20261 min read

What is JSON? JSON, short for JavaScript Object Notation, is a plain text format for writing down structured data, such as a customer with a name, an email and a list of orders. Apps use it to send information to each other, and AI tools use it to hand back answers a program can read. If you can read a labelled list, you can read JSON.

MDN calls it "a standard text-based format for representing structured data based on JavaScript object syntax" and adds that it "represents structured data as a string, which is useful when you want to transmit data across a network." The standard behind it, RFC 8259, describes it as "a lightweight, text-based, language-independent data interchange format." Language-independent is the part that explains its popularity. A Python backend, a JavaScript front end and an AI model can all exchange JSON without caring what the other is written in.

A first look

Here is a customer record in JSON. The details are invented for the example.

json
{
  "name": "Maya Okafor",
  "email": "maya@example.com",
  "active": true,
  "orders": [
    { "id": 1041, "total": 86.5 },
    { "id": 1057, "total": 12 }
  ],
  "notes": null
}

Read it like this. Curly braces wrap an object, which is a set of labelled values. Each label (called a key) sits in double quotes, followed by a colon and its value. Square brackets wrap an array, an ordered list. Commas separate items. That is nearly the whole grammar.

What can go inside

Per RFC 8259, a value can be an object, an array, a number, a string, or one of three lowercase words: true, false and null. The RFC states that "no other literal names are allowed." MDN adds what is left out: JSON "cannot contain undefined, NaN, or Infinity", and it cannot hold functions or dates as such.

Type

Example

Notes

String

"hello"

Always double quotes

Number

86.5

No quotes, no currency symbols

Boolean

true

Lowercase only

Null

null

Means "no value here"

Array

[1, 2, 3]

Ordered list

Object

{"a": 1}

Labelled values

Dates have no special type, so apps write them as strings, usually in a standard layout such as "2026-11-03". That is a convention, not a feature of the format.

The five mistakes that break JSON

When a program says "unexpected token" or "invalid JSON", it is almost always one of these. AI tools make every one of them, especially when they paste JSON into a chat answer and decorate it.

1. Single quotes. MDN is explicit: "Strings must be enclosed in double quotes, not single quotes."

Broken:  { 'name': 'Maya' }
Fixed:   { "name": "Maya" }

2. Unquoted keys. Property names must also be in double quotes.

Broken:  { name: "Maya" }
Fixed:   { "name": "Maya" }

3. Trailing commas. MDN notes that "objects and arrays cannot contain trailing commas." This is the most common AI slip, because many programming languages allow them.

Broken:  { "a": 1, "b": 2, }
Fixed:   { "a": 1, "b": 2 }

4. Comments. The RFC grammar has no comment syntax, so a line starting with two slashes makes the whole document invalid, even though it looks helpful.

Broken:  { "a": 1 // the first value }
Fixed:   { "a": 1 }

5. Wrong literals. Capitalised True or None, which come from Python, are not valid. Use true and null.

Broken:  { "active": True, "notes": None }
Fixed:   { "active": true, "notes": null }

A sixth mistake is not about syntax at all: extra text around the JSON. If a model answers "Here is your data:" followed by the object, the introduction makes the whole reply unparseable.

How to check JSON in ten seconds

Paste it into any free online JSON validator, or into your browser's developer console wrapped in a parse call. Either one will point at the first line that breaks the rules. Fix that line, run it again, and repeat. Errors often cascade, so one fix can clear several messages.

Asking an AI for JSON your code can use

If your app depends on a model returning data, a few habits cut failures sharply:

  1. Show the shape. Paste one complete example object and say "return an array of objects with exactly these keys."

  2. Say what to leave out. "Return only the JSON, no explanation, no code fences."

  3. Fix the allowed values. For a field like status, list the permitted words.

  4. Tell it what to do when data is missing. "Use null, never an empty string."

  5. Validate anyway. Never assume a model returned valid JSON. Run it through a parser and handle the failure.

For the deeper techniques, including settings that force valid output, see how to get JSON output from AI and the explainer on what structured output means in AI.

Where you will meet JSON in an AI-built app

  • API responses. Almost every web service answers in JSON, which is why what an API is is a natural companion to this article.

  • Configuration files. Settings for your project often live in files ending in .json.

  • Tool calling. When a model asks your app to run a function, it describes the call as JSON, as explained in what function calling is in AI.

  • Stored data. Many databases accept JSON columns for flexible fields.

All of these sit inside the wider toolkit covered in the pillar guide to AI coding tools.

Frequently asked questions

What does JSON stand for?

JavaScript Object Notation. It borrows its look from JavaScript, but it is a separate text format that nearly every programming language can read and write.

Is JSON a programming language?

No. It is only a way of writing data down. It cannot run code, make decisions or repeat anything. A program has to read it and do something with the values.

What is the difference between JSON and a JavaScript object?

A JavaScript object lives inside a running program and can contain functions and other things. JSON is text that follows stricter rules, such as double-quoted keys and no trailing commas, so it can be sent anywhere.

Why does my app say "invalid JSON"?

Look for single quotes, a trailing comma, a comment, a capitalised True or None, or extra words before or after the object. A validator will show you the exact line.

Can JSON contain comments?

No. The grammar defines no comment syntax. If you need notes, put them in a separate field such as "description", or in a different file.

How did this land?

About the author

Steve Jefferson
Steve Jefferson

Developer Advocate

Steve builds something with Swarmz every week and writes up what worked, what broke, and what he'd do differently. Tutorials and hands-on guides are his lane.

Share

Get the next post in your inbox

One email a month. Product updates, engineering posts, and the best of Built with Swarmz.

I agree to receive emails about AI building tips and Swarmz product news. Unsubscribe any time.