JSON Schema Validation: Contracts, Required Fields, and API Mistakes to Avoid
Learn JSON Schema basics — types, required properties, common API contract errors — and how to validate payloads in the browser before you commit or deploy.
The complete guide to prettifying, validating, repairing, and debugging JSON in production workflows — without leaking sensitive API data to remote servers.
By codefunc
JSON is the lingua franca of modern web APIs, configuration files, CI artifacts, and log pipelines. When a webhook fails, a deploy breaks, or a client reports "invalid JSON," you need to read the payload fast, find the syntax error, and move on — often under time pressure. Browser-based formatters are the fastest path, but only if you understand what happens to your data and which mistakes cost hours in production.
Bottom line: Format JSON to make it readable. Validate JSON to fail before JSON.parse does. Use client-side tools when payloads contain secrets. Never trust auto-repair on production config without reviewing every changed byte.
This article is written for frontend engineers, full-stack developers, DevOps folks debugging pipeline output, and technical writers preparing API examples. If you paste production responses, OAuth tokens, or customer records into online tools, the privacy sections matter as much as the syntax rules.
JSON (JavaScript Object Notation) is a text format defined by ECMA-404 and RFC 8259. It is not the same as a JavaScript object literal, though the syntax looks similar.
| Type | Example | Notes |
|---|---|---|
| Object | {"a": 1} |
Keys must be double-quoted strings |
| Array | [1, 2, 3] |
Ordered list |
| String | "hello" |
Double quotes only; escape with \ |
| Number | 42, -3.14, 1e6 |
No NaN or Infinity |
| Boolean | true, false |
Lowercase only |
| Null | null |
Lowercase only |
Anything else — undefined, functions, Date objects, BigInt without serialization, comments — is invalid in strict JSON.
| Format | Comments | Trailing commas | Unquoted keys | Typical use |
|---|---|---|---|---|
| JSON | No | No | No | APIs, interchange |
| JSONC | // and /* */ |
Often allowed | No | tsconfig.json, VS Code settings |
| JSON5 | Yes | Yes | Yes | Human-authored config |
Tools labeled "JSON formatter" usually target strict JSON. Pasting JSONC into a strict validator will fail — strip comments first or use an editor that understands JSONC.
Minified JSON is optimal on the wire:
{"user":"ada","roles":["admin","editor"],"active":true,"meta":{"lastLogin":"2026-07-05T10:00:00Z"}}
Pretty-printed JSON is optimal for humans:
{
"user": "ada",
"roles": ["admin", "editor"],
"active": true,
"meta": {
"lastLogin": "2026-07-05T10:00:00Z"
}
}
Formatting helps you:
} is obvious with indentationValidation confirms the text is parseable before your application, test suite, or CI job runs JSON.parse.
Follow this sequence when handling sensitive or production data:
.json file, clipboard from Slack. Know whether the payload may contain PII or credentials.Rule of thumb: If you would not paste it into a public Slack channel, do not paste it into a server-side formatter.
{
"id": "usr_8f2a",
"email": "ada@example.com",
"roles": ["admin", "editor"],
"active": true,
"quota": null
}
{
user: "ada",
roles: ['admin'],
active: true,
created: new Date(),
extra: undefined,
}
Problems: unquoted keys, single-quoted strings, new Date(), undefined, trailing comma.
{
"count": 01,
"label": "Line 1
continues",
"ratio": .5
}
Problems: leading zero on integer, unescaped newline in string, some parsers reject .5 without a leading zero (use 0.5).
| Error message | Root cause | Fix |
|---|---|---|
Unexpected token } |
Trailing comma, extra }, missing value |
Remove trailing comma; balance braces |
Unexpected token ' in JSON |
Single-quoted string | Use double quotes |
Unexpected end of JSON input |
Truncated copy/paste | Re-copy full payload; check log rotation |
Expected ',' or '}' |
Missing comma between properties | Add comma on previous line |
Unexpected token u |
Bare undefined |
Remove key or use null |
Cannot convert undefined |
Empty input | Verify clipboard; check proxy stripped body |
When JSON fails in production but "worked in Postman":
\uFEFFSyntax validation asks: "Is this valid JSON?" Schema validation asks: "Does this JSON match the shape we expect?"
Use JSON Schema when:
A syntactically valid document can still be semantically wrong:
{
"price": "29.99",
"quantity": "two",
"sku": null
}
Types are wrong (price should be number, sku should be string). Schema validators catch this; formatters do not.
| Scenario | Best tool | Why |
|---|---|---|
| Quick one-off format in a meeting | Browser (client-side) | Zero setup |
| Production secret in payload | Browser (client-side) | No network exfiltration |
Daily .json editing in a repo |
IDE + format-on-save | Git integration |
| CI/CD pipeline gates | jq, python -m json.tool, native parser |
Scriptable, auditable |
| 50 MB log file | CLI stream parser | Browsers choke on huge paste |
| Schema enforcement | ajv, jsonschema CLI |
Repeatable rules |
jq one-liners worth knowing# Pretty-print a file
jq . response.json
# Extract a field
jq '.data.items[0].id' response.json
# Validate parse only (exit 1 on error)
jq empty response.json
Browser tools complement — they do not replace — CLI workflows.
When a tool runs JavaScript in your browser with no network calls for the payload:
For incident response, redact tokens first:
{
"authorization": "[REDACTED]",
"user": { "email": "a***@example.com" }
}
Log aggregators often emit one JSON object per line. Standard formatters expect a single value. Split by newline and format each line individually, or use jq -c for compaction.
Browsers handle pasted JSON up to a few megabytes reasonably. Beyond that:
Formatting is O(n) in document size — acceptable for API responses, not for multi-GB exports.
jq empty on every committed .json filetsconfig.json is JSONC, not JSON)null explicitly — absent keys and null mean different things in many APIsUse these codefunc tools alongside this guide:
Treat JSON formatting as a readability step and validation as a gate. Use client-side tools for speed and privacy when data is sensitive. Fix errors one at a time from the first reported position. Reserve auto-repair for development copies, never blind production deploys. Pair browser tools with CLI validation in CI for defense in depth.
Learn JSON Schema basics — types, required properties, common API contract errors — and how to validate payloads in the browser before you commit or deploy.
Why compact GraphQL queries hurt reviews, how to format selection sets consistently, and a browser workflow before you paste into Apollo or GraphiQL.
Use JSONPath to extract fields, filter arrays, and inspect nested API payloads — with practical expressions and a browser tester workflow.
Find a developer tool