| | |

JSON 22 ๐Ÿ“„ Cheatsheet

โฑ๏ธ Estimated read: 6 min | |

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.

TypeSyntaxExample
StringThe double quotes"text"
NumberThe decimal42, 3.14, 1e10
BooleanThe literaltrue, false
NullThe literalnull
ObjectThe {} braces{"key": "value"}
ArrayThe [] 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.

EscapeCharacter
\"The double quote
\\The backslash
\/The solidus
\bThe backspace
\fThe form feed
\nThe line feed
\rThe carriage return
\tThe tab
\uXXXXThe 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.

FunctionPurposeEdge case
JSON.parse(text, reviver)Parse the string to the valueThe large integers are rounded
JSON.stringify(value, replacer, space)Serialize the value to the stringThe 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.

KeywordPurpose
typeThe core type assertion
propertiesThe object property subschemas
requiredThe required property names
itemsThe array element subschema
enumThe closed value set
patternThe regex constraint
$refThe schema reference
allOfThe conjunction
anyOfThe disjunction
oneOfThe 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.

PointerResolves to
""The whole document
/The member with the empty name
/fooThe foo member
/foo/0The first element of the foo array
/a~1bThe 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.

OperationMembersBehaviour
addpath, valueInsert or replace
removepathDelete
replacepath, valueReplace
movefrom, pathRemove and add
copyfrom, pathDeep copy and add
testpath, valueThe 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.

ToolStyleUse for
jqThe command-line filterThe shell processing
JSONPathThe query languageThe cross-language extraction
JSON PointerThe addressThe single value reference
AjvThe schema compilerThe 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.

LibraryDraftLanguage
Ajvdraft-07 by default, 2019-09 and 2020-12 by the importJavaScript
ajv-formatsThe standard formatsJavaScript
json-schema-to-typescriptThe type generationTypeScript

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.

FormatSizeThe determinism
BSON85.8% to 106.7%No
MessagePack50.5% to 87.9%No
CBOR50.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.

LibraryStyleEnvironment
oboeThe selector-basedThe browser and the Node.js
bfjThe SAX-style eventsThe 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.

RuleDetail
The member sortingThe UTF-16 code units, recursive
The number serializationThe ECMAScript Number::toString
The string escapingThe minimal set
The duplicate keysThe rejected
The NaN and the InfinityThe 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

AreaKey takeaway
The grammarThe six value types, the strict punctuation
The escapingThe ~0 and the ~1, the surrogate pair
The parse and the stringifyThe reviver and the replacer, the prototype pollution
The JSON SchemaThe validation keywords, the composition
The JSON PointerThe `/-separated tokens, the escapes
The JSON PatchThe six operations, the atomicity
The query toolsThe jq, the JSONPath, the JSON Pointer
The binary formatsThe BSON, the MessagePack, the CBOR
The streamingThe oboe, the bfj
The canonicalizationThe 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.

Was this helpful?


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!