JSON 22 ๐ Cheatsheet
JSON is a text format with six value types, a strict grammar, and a set of tools that handle the parsing, the validation, the querying, and the serialization. The cheat sheet is scoped to the decisions a developer makes mid-task: how to write the valid JSON, how to validate it against a schema, how to query it, and which tool to reach for. It is not a list of every feature in every library. It is the set of patterns that come up repeatedly.
The Grammar
The six value types, the punctuation, and the rules that the strict parser enforces.
| Type | Syntax | Example |
|---|---|---|
| String | The double quotes | "text" |
| Number | The decimal | 42, 3.14, 1e10 |
| Boolean | The literal | true, false |
| Null | The literal | null |
| Object | The {} braces | {"key": "value"} |
| Array | The [] brackets | ["a", "b"] |
The strict JSON rejects the comments, the trailing commas, the single quotes, and the unquoted keys. The undefined, the NaN, and the Infinity are not valid JSON. The strings must be the double-quoted, and the control characters must be escaped.
The String Escapes
The escape sequences and the Unicode representation.
| Escape | Character |
|---|---|
\" | The double quote |
\\ | The backslash |
\/ | The solidus |
\b | The backspace |
\f | The form feed |
\n | The line feed |
\r | The carriage return |
\t | The tab |
\uXXXX | The Unicode code point |
The characters outside the BMP use the surrogate pair. The G clef (U+1D11E) is \uD834\uDD1E, and the emoji (U+1F600) is \uD83D\uDE00. The unpaired surrogates are allowed by the grammar but the behavior is unpredictable.
The Parse and the Stringify
The two functions that every JavaScript developer uses.
| Function | Purpose | Edge case |
|---|---|---|
JSON.parse(text, reviver) | Parse the string to the value | The large integers are rounded |
JSON.stringify(value, replacer, space) | Serialize the value to the string | The circular reference throws |
The reviver is the transformation hook, and the replacer is the filter. The space is the indentation. The toJSON() method is the custom serialization, and the Date uses it to serialize as the ISO string.
The prototype pollution of the reviver is the security hazard. The JSON.parse(text, this.parseReviver) is the pattern that the Axios CVE-2026-42044 exploited, and the own-property check is the defense.
The JSON Schema
The validation keywords and the composition.
| Keyword | Purpose |
|---|---|
type | The core type assertion |
properties | The object property subschemas |
required | The required property names |
items | The array element subschema |
enum | The closed value set |
pattern | The regex constraint |
$ref | The schema reference |
allOf | The conjunction |
anyOf | The disjunction |
oneOf | The exclusive disjunction |
The required checks the presence, not the value. The allOf with the additionalProperties is the trap, and the unevaluatedProperties is the 2020-12 fix. The format is the annotation-only by default in 2020-12.
The JSON Pointer
The address for the specific value in the document.
| Pointer | Resolves to |
|---|---|
"" | The whole document |
/ | The member with the empty name |
/foo | The foo member |
/foo/0 | The first element of the foo array |
/a~1b | The a/b member |
The ~0 is the ~, and the ~1 is the /. The unescape order matters: the ~1 first, the ~0 second. The - token is the append position for the JSON Patch.
The JSON Patch
The operations that transform the document.
| Operation | Members | Behaviour |
|---|---|---|
add | path, value | Insert or replace |
remove | path | Delete |
replace | path, value | Replace |
move | from, path | Remove and add |
copy | from, path | Deep copy and add |
test | path, value | The precondition check |
The patch is atomic with the HTTP PATCH. The test failure aborts the entire patch. The add with the - index appends to the array.
The Query Tools
The tools for the different query styles.
| Tool | Style | Use for |
|---|---|---|
jq | The command-line filter | The shell processing |
JSONPath | The query language | The cross-language extraction |
JSON Pointer | The address | The single value reference |
Ajv | The schema compiler | The runtime validation |
The jq is the .foo and the .foo | .bar and the map() and the select(). The JSONPath is the $..author and the $..book[?(@.price<10)]. The JSON Pointer is the /foo/0. The Ajv is the ajv.compile(schema).
The Validation Libraries
The libraries and the draft support.
| Library | Draft | Language |
|---|---|---|
Ajv | draft-07 by default, 2019-09 and 2020-12 by the import | JavaScript |
ajv-formats | The standard formats | JavaScript |
json-schema-to-typescript | The type generation | TypeScript |
The Ajv compiles the schema into the function. The validate.errors is the failure details. The allErrors: true collects every failure.
The Binary Formats
The three binary formats and the trade-offs.
| Format | Size | The determinism |
|---|---|---|
| BSON | 85.8% to 106.7% | No |
| MessagePack | 50.5% to 87.9% | No |
| CBOR | 50.5% to 88.0% | Yes |
The BSON is the MongoDB storage with the field-name overhead. The MessagePack is the compact general-purpose format. The CBOR is the IETF standard with the deterministic encoding.
The Streaming Parsers
The parsers for the large files.
| Library | Style | Environment |
|---|---|---|
oboe | The selector-based | The browser and the Node.js |
bfj | The SAX-style events | The Node.js |
The oboe fires the .node() callback for the matching node. The bfj fires the bfj.events.property and the other events. The yieldRate controls the event loop yielding.
The Canonical JSON
The deterministic serialization for the cryptographic operations.
| Rule | Detail |
|---|---|
| The member sorting | The UTF-16 code units, recursive |
| The number serialization | The ECMAScript Number::toString |
| The string escaping | The minimal set |
| The duplicate keys | The rejected |
| The NaN and the Infinity | The rejected |
The RFC 8785 JCS is the standard. The 1e21 becomes the 1e+21, and the -0 becomes the 0.
The One-Line Summary
The strict grammar. The schema validation. The pointer address. The patch mutation. The query tools. The binary alternatives. The streaming parsers. The canonical bytes.
The JSON is the text format with the six value types. The schema is the validation contract. The pointer is the address. The patch is the mutation. The jq and the JSONPath are the query tools. The BSON, the MessagePack, and the CBOR are the binary alternatives. The oboe and the bfj are the streaming parsers. The RFC 8785 is the canonicalization for the cryptographic operations.
Summary
| Area | Key takeaway |
|---|---|
| The grammar | The six value types, the strict punctuation |
| The escaping | The ~0 and the ~1, the surrogate pair |
| The parse and the stringify | The reviver and the replacer, the prototype pollution |
| The JSON Schema | The validation keywords, the composition |
| The JSON Pointer | The `/-separated tokens, the escapes |
| The JSON Patch | The six operations, the atomicity |
| The query tools | The jq, the JSONPath, the JSON Pointer |
| The binary formats | The BSON, the MessagePack, the CBOR |
| The streaming | The oboe, the bfj |
| The canonicalization | The RFC 8785, the deterministic bytes |
Remember: The JSON is the text format with the six value types and the strict grammar. The schema is the validation contract. The pointer is the address. The patch is the mutation. The jq and the JSONPath are the query tools. The BSON, the MessagePack, and the CBOR are the binary alternatives. The oboe and the bfj are the streaming parsers. The RFC 8785 is the canonicalization. The cheat sheet is the decisions, and the decisions are the discipline.
Stop using slow, ad-bloated tool sites! ๐คฎ
๐ Search “KandZ Tools” on Google to use many professional utilities for free.
KandZ.me is the ultimate minimalist hub for:
โ
Finance (Mortgage, Interest, Inflation)
โ
Tech (Base64, JSON, Dev Suite, IP)
โ
Health (BMI, BMR, TDEE)
โ
Productivity (Timer, Workspace, QR)
โก๏ธ Fast & Private
๐ No data leaves your device
๐ 100% Free
๐ Use it now: https://tools.kandz.me
๐ Bookmark itโyouโll need it later!