JSONFormat — jsonformat.co

JSON Schema Validation — Cheat Sheet

Dev Tools Weekly Cheat Sheet

Use the JSON syntax validator to check whether a document parses. Use the JSON Schema Validator when you also need to check required fields, types, or value constraints. The schema tool reports unsupported keywords; review those warnings before relying on a result.


JSON Syntax Rules (The Basics)

RuleValid ✅Invalid ❌
Strings use double quotes"name"'name' or name
Keys must be quoted{"key": 1}{key: 1}
No trailing commas[1, 2, 3][1, 2, 3,]
No comments—// comment or /* */
No single quotes"hello"'hello'
No undefinednullundefined
Numbers: no leading zeros0.505 or .5
No hex numbers2550xFF
No Infinity/NaNuse nullInfinity, NaN

JSON Data Types

TypeExampleNotes
String"hello"UTF-8, escaped with \
Number42, 3.14, -1, 2.5e10No hex, octal, or Infinity
Booleantrue, falseLowercase only
NullnullLowercase only
Array[1, "two", null]Ordered, mixed types OK
Object{"key": "value"}Unordered key-value pairs

Common Parse Errors & Fixes

1. Unexpected Token

SyntaxError: Unexpected token ' in JSON at position 5

Cause: Single quotes instead of double quotes.

Fix: Use double quotes around property names and string values. Preserve apostrophes inside the string itself.

2. Trailing Comma

SyntaxError: Unexpected token } in JSON at position 28

Cause: {"a": 1, "b": 2,} — comma before closing brace/bracket.

Fix: Remove the last comma.

3. Unescaped Special Characters

SyntaxError: Unexpected token (newline) in JSON

Cause: String contains literal newline, tab, or backslash.

Fix: Escape them: \n, \t, \\.

4. Unquoted Keys

SyntaxError: Unexpected token k in JSON

Cause: {key: "value"} — keys must be quoted.

Fix: {"key": "value"}.

5. Missing Comma

SyntaxError: Expected ',' or '}' after property value

Cause: Missing comma between properties.

Fix: Add commas between all key-value pairs.


JSON Schema — Quick Reference

Basic Structure

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "name": { "type": "string" },
    "age": { "type": "integer", "minimum": 0 },
    "email": { "type": "string", "format": "email" }
  },
  "required": ["name", "email"]
}

Type Keywords

TypeValidatesExtra Keywords
stringTextminLength, maxLength, pattern, format
numberAny numberminimum, maximum, multipleOf, exclusiveMinimum
integerWhole numbersSame as number
booleantrue/false—
nullnull only—
arrayArraysitems, minItems, maxItems, uniqueItems
objectObjectsproperties, required, additionalProperties

String Formats

format is an annotation by default in Draft 2020-12. A validator must support and enable format assertions to reject a value on that basis. The examples below describe format names, not a guarantee that every validator checks them. See the JSON Schema format vocabulary.

FormatValidatesExample
"email"Email addressuser@example.com
"uri"Full URIhttps://example.com/path
"date"ISO 8601 date2026-02-04
"date-time"ISO 8601 datetime2026-02-04T12:00:00Z
"time"ISO 8601 time12:00:00Z
"ipv4"IPv4 address192.168.1.1
"ipv6"IPv6 address::1
"uuid"UUID550e8400-e29b-41d4-a716-446655440000
"hostname"Internet hostnameexample.com
"regex"ECMA regex^[a-z]+$

Composition Keywords

// Must match ALL schemas
{ "allOf": [{ "type": "string" }, { "minLength": 1 }] }
// Must match at least ONE
{ "anyOf": [{ "type": "string" }, { "type": "number" }] }
// Must match EXACTLY one
{ "oneOf": [{ "type": "string" }, { "type": "integer" }] }
// Must NOT match
{ "not": { "type": "null" } }
// Conditional
{ "if": { "properties": { "type": { "const": "business" }}},
  "then": { "required": ["company"] },
  "else": { "required": ["firstName"] }
}

Common Patterns

Enum (fixed values):

{ "type": "string", "enum": ["active", "inactive", "pending"] }

Nested object:

{
  "type": "object",
  "properties": {
    "address": {
      "type": "object",
      "properties": {
        "street": { "type": "string" },
        "city": { "type": "string" },
        "zip": { "type": "string", "pattern": "^[0-9]{5}$" }
      },
      "required": ["street", "city"]
    }
  }
}

Array of objects:

{
  "type": "array",
  "items": {
    "type": "object",
    "properties": {
      "id": { "type": "integer" },
      "name": { "type": "string" }
    },
    "required": ["id", "name"]
  },
  "minItems": 1,
  "uniqueItems": true
}

Debugging JSON — Pro Tips

  1. Validate first, debug second. Paste into the JSON syntax validator — it shows the exact line and column of errors.
  2. Minified JSON unreadable? Pretty-print it. Most errors become obvious with indentation.
  3. Copy from API response? Watch for trailing content — some APIs return multiple JSON objects (NDJSON).
  4. Unicode issues? JSON exchanged between systems uses UTF-8. Parsers differ in whether they ignore a leading BOM; omit it when producing JSON. See RFC 8259.
  5. Large numbers? JavaScript loses precision above 2^53 - 1 (9007199254740991). Use strings for big IDs.

jq Cheat Sheet (CLI JSON Processing)

CommandWhat It Does
jq '.'Pretty-print
jq '.name'Extract field
jq '.users[0]'First array element
jq '.users[] | .name'All names from array
jq 'length'Count elements
jq 'keys'List object keys
jq 'select(.age > 21)'Filter
jq '{name, email}'Pick fields
jq -r '.url'Raw output (no quotes)
jq -c '.'Compact (minify)

🛠 Format & validate JSON instantly: jsonformat.co

More JSON guides: JSONFormat articles