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.
Use JSONPath to extract fields, filter arrays, and inspect nested API payloads — with practical expressions and a browser tester workflow.
By codefunc
API responses rarely arrive as flat maps. You get data.items[].meta.flags, nested carts, or GraphQL-shaped trees dumped as JSON. Writing one-off for loops in a scratch file works until the path changes again. JSONPath gives you a compact query language for those trees — select nodes, filter arrays, and copy only what you need for a bug report.
Bottom line: Start paths with $. Prefer $.a.b[*].c for lists and [?(@.price<10)] for filters. Pretty-print first with a JSON Formatter, then probe with the JSONPath Tester. Validate contracts with JSON Schema Validator when the shape itself is the bug.
Frontend and full-stack developers inspecting REST/GraphQL JSON fixtures, support engineers reducing huge payloads to the failing node, and anyone comparing “what the docs say” vs “what production returned.”
| Expression | Meaning |
|---|---|
$ |
Root document |
$.store.book |
Property path |
$.store.book[0] |
Array index |
$.store.book[*].title |
All titles |
$.store.book[0:2] |
Slice |
$..price |
Recursive descent |
$.store.book[?(@.price<10)] |
Filter |
For HTML/XML trees use XPath / CSS Selector Tester instead — JSONPath is for JSON only.
$.data or $.store.book[*]), then narrow.# Cheap books
$.store.book[?(@.price<10)]
# Fiction only
$.store.book[?(@.category=='fiction')]
# Titles of everything under store
$.store..title
Keep filters simple: @.field, comparisons (==, !=, <, >), and string/number literals. Complex script expressions belong in application code, not a one-line path.
| Mistake | Fix |
|---|---|
Path without $ |
Always start with $ |
| Expecting object keys as rows | Use [*] or recursive .. |
| Comparing strings without quotes | Use 'fiction' / "fiction" in filters |
| Assuming one match returns a scalar | Testers often wrap results in an array |
Treat JSONPath as a microscope for payloads, not a query engine for production databases. Format → path → schema. Keep expressions short enough to paste into a ticket. Use the JSONPath Tester whenever a nested field “should be there” but the UI shows empty.
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.
How to convert between CSV and JSON safely — quoting, nested objects, type coercion, headers, and a workflow that catches breakage before it hits production.
Find a developer tool