Stax
Tools

JSON Cheat Sheet

JSON syntax reference: data types, escape characters, JSON5 differences, common pitfalls, and date conventions.

Data types

TypeExampleNotes
string"hello"Double quotes only. UTF-8.
number42 or 3.14 or -1.2e10No NaN, no Infinity.
booleantrue or falseLowercase only.
nullnullLowercase. Means "explicitly absent."
object{ "key": "value" }Keys MUST be double-quoted strings.
array[1, 2, 3]Ordered list, mixed types allowed.

Escape sequences inside strings

SequenceCharacter
\"Double quote
\\Backslash
\/Forward slash (optional escape)
\nNewline
\rCarriage return
\tTab
\bBackspace
\fForm feed
\uXXXXUnicode codepoint (4 hex digits)

Valid vs invalid

✓ Valid

{
  "name": "Alice",
  "age": 30,
  "tags": ["admin", "user"],
  "deleted_at": null
}

✗ Invalid

{
  name: 'Alice',     // unquoted key, single quote
  age: NaN,          // NaN not allowed
  tags: ['admin',],  // trailing comma
  // deleted_at      // comment not allowed
}

JSON vs JSON5 vs JSONC vs YAML

FeatureJSONJSONCJSON5YAML
Comments✅ // and /* */✅ #
Trailing commasN/A
Unquoted keys
Single quotes
Multi-line strings
Hex / Inf / NaNLimited
Native browser support
Use caseAPIs, storageVS Code configsHuman-edited configsCI/CD, K8s

Date conventions

FormatExampleNotes
ISO 8601 (UTC)"2026-05-06T14:23:45Z"Standard for APIs. Z = UTC.
ISO 8601 (offset)"2026-05-06T14:23:45+05:30"With timezone offset.
Unix seconds1746557025Compact, no timezone ambiguity.
Unix milliseconds1746557025000JavaScript Date.now() format.

Common gotchas

  • JSON.parse(undefined) throws. Always JSON.parse(string), where string is non-undefined.
  • JSON.stringify(undefined) === undefined. undefined values in objects are silently dropped.
  • Numbers lose precision beyond 2^53 (~9 quadrillion). Use string representation for IDs, big integers, or amounts.
  • No circular references — JSON.stringify throws on circular objects. Break the cycle or use a library like flatted.
  • Sorting keys isn't guaranteed — most parsers preserve insertion order, but the spec doesn't require it. Don't rely on key ordering for security or comparison.
  • Date objects become ISO strings in JSON.stringify. To rehydrate, use a reviver: JSON.parse(s, (k, v) => /^\d{4}-\d{2}-\d{2}/.test(v) ? new Date(v) : v).

Format and validate JSON with our JSON Formatter, or browse JSON visually in the JSON Tree Viewer.

JSONの仕様をひと言で

ユースケースとフレーバーの選択

JSON(JavaScript Object Notation)は構造化データのためのテキストフォーマットです。6つのデータ型:文字列・数値・真偽値・null・オブジェクト(キーと値のペア)・配列(順序付きリスト)。文字列はダブルクォートのみを使用します。オブジェクトのキーは引用符で囲む必要があります。コメントなし・末尾のカンマなし・undefinedなし・NaNなし・Infinityなし。これが仕様のすべてです。

HTTP API:厳格なJSON。VS Code / TypeScript設定:JSONC。人間が編集する設定ファイル:JSON5またはYAML。ストレージフォーマット:厳格なJSONまたはBSON(バイナリ)。迷ったときはデフォルトで厳格なJSONにしてください。最も普遍的に解析可能です。

バックエンド開発者はAPIペイロードを仕様に対して検証したり、テストフィクスチャを書いたり、サードパーティの統合からの解析エラーをデバッグする際にこのリファレンスを参照します。フロントエンドエンジニアは動的文字列を構築する際のエスケープシーケンスの構文を再確認するために使用します。DevOpsエンジニアはTerraform・GitHub Actions・AWS CloudFormationのJSON設定ファイルを作成する際に参照します。厳格なパーサーでは末尾のカンマが静かな失敗を引き起こすためです。

設定ファイルをコミットする前に必ずリンターでJSONを検証してください。誤ったカンマはデプロイを静かに壊します。デバッグ中の人間が読める出力にはJSON.stringify(obj, null, 2)を使用してください。大きなペイロードは転送前に最小化してください。見やすくフォーマットされた状態と最小化された状態の差はバイトサイズで30〜40%になることがあります。JavaScriptパーサーでの精度の損失を避けるために2^53を超える数値IDは文字列として保存してください。

REST APIを構築するフルスタック開発者は、どの型が有効で文字列値のエッジケースの文字をどのようにエスケープするかを知る必要があります。PostmanやInsomniaのテストスイートを書くQAエンジニアはリクエストボディを作成する際に参照します。ETLパイプラインを構築するデータエンジニアは、パイプラインツールが受け付けるものが異なる場合に厳格なJSONとJSON5の違いを理解するために使用します。コーディング面接の準備をしている学生は、トリッキーなコーナーケースについてMDNより深い簡潔な仕様リファレンスとしてブックマークします。

よくある質問

What's the difference between JSON, JSON5, and JSONC?
JSON is the strict spec — no comments, no trailing commas, no unquoted keys, double quotes only. JSONC (JSON with Comments) adds // and /* */ comments — Microsoft uses it for tsconfig.json, .vscode/settings.json. JSON5 is more permissive — adds comments, trailing commas, single quotes, unquoted keys, hex numbers. None of these are interchangeable with strict JSON in production APIs — the API spec dictates which flavor to use.
Why do trailing commas break JSON?
Strict JSON forbids trailing commas after the last element of arrays and objects. JavaScript allows them, so developers paste JS-like data and get parse errors. JSON5 and JSONC allow trailing commas. If you need JSON output that other systems will consume, never include them. JSON.stringify() in JavaScript correctly omits trailing commas.
Can JSON have comments?
Strict JSON cannot. Comments were intentionally excluded by Douglas Crockford (JSON's creator) to keep the format minimal. If you need comments, use JSON5 or JSONC. As a workaround in strict JSON, some teams use a special key like '_comment' to embed notes — though this clutters the data.
How do I represent dates in JSON?
Use ISO 8601 strings: '2026-05-06T14:23:45Z' (UTC) or '2026-05-06T14:23:45+05:30' (with offset). This is the de facto standard in 95% of APIs. Alternatives: Unix timestamps as integers (1746557025) — concise but less human-readable. Avoid local-format strings ('5/6/2026') — they're ambiguous between US and rest-of-world conventions.
Why are some characters showing as \u00XX in JSON?
JSON escape sequences. Characters outside ASCII or with special meaning (", \\, /) are escaped as \u followed by 4 hex digits. JSON.stringify() escapes these by default for safety. To get human-readable Unicode, parse and re-stringify in your application code, or use JSON.stringify(obj, null, 2) which preserves Unicode in modern engines.

関連ツール