EXPLAINER

JSON Fundamentals for API Work

JSON is a text format for structured data — objects, arrays, strings, numbers, booleans and null — used by almost every modern HTTP API and by model tool arguments.

Short answer: JSON is the common data text format for APIs: nested objects and arrays you can parse in any language. AI APIs and tool calls lean on it heavily.

What is it?

JSON (JavaScript Object Notation) is a language-independent text format. It supports objects ({}), arrays ([]), strings, numbers, booleans and null. Web APIs request and respond with JSON bodies; many LLM tool calls pass JSON arguments (Function Calling (Tool Calling) Explained).

Why it matters

If you cannot read JSON, you cannot debug model APIs, RAG metadata or browser fetch calls. Almost every AI integration tutorial assumes JSON literacy.

How to do it

Rules of thumb:

  • Keys are strings in double quotes.
  • No trailing commas; no comments in standard JSON.
  • Parse with a real parser (JSON.parse, json.loads) — never with fragile regex.
  • UTF-8 encoding is the norm.
  • Pretty-print for humans; minify on the wire if you want.

Map JSON to typed structures in TypeScript or dicts/lists in Python, then validate.

Example

{
  "model": "your-model-id",
  "messages": [
    {"role": "user", "content": "Hello"}
  ],
  "temperature": 0.2
}

A response might nest the answer under choices[0].message.content — path depends on the provider.

When to use it

Use JSON for APIs, config that is data-not-code, and tool arguments. Use CSV for flat tables shared with spreadsheets; use databases for concurrent writes (Databases for AI Applications).

Practical notes

JSON appears in config files, HTTP bodies, log lines and LLM tool arguments. Learn to spot invalid documents quickly: smart quotes from word processors, unescaped newlines inside strings, and 'NaN'/'Infinity' which are not valid JSON numbers. Use a formatter while developing, but keep parsers strict in production. When models generate JSON, ask for schema-constrained output if your provider supports it, then still validate (How to Validate JSON). Binary data does not belong in JSON without Base64, and huge Base64 blobs punish context windows. Prefer separate file storage for large artifacts and store only references in JSON metadata. Work through one real request end to end, write down the failure modes you observed, and add a regression test so the next change does not silently drop validation, auth, or logging. Prefer boring, reviewable code over a clever abstraction until the second or third product needs the same pattern. Work through one real request end to end, write down the failure modes you observed, and add a regression test so the next change does not silently drop validation, auth, or logging. Prefer boring, reviewable code over a clever abstraction until the second or third product needs the same pattern. Work through one real request end to end, write down the failure modes you observed, and add a regression test so the next change does not silently drop validation, auth, or logging. Prefer boring, reviewable code over a clever abstraction until the second or third product needs the same pattern. Work through one real request end to end, write down the failure modes you observed, and add a regression test so the next change does not silently drop validation, auth, or logging. Prefer boring, reviewable code over a clever abstraction until the second or third product needs the same pattern.

Common mistakes

  • Single quotes (invalid in standard JSON).
  • Trailing commas from copy-pasted JS objects.
  • Treating a string that looks like JSON as already parsed.