Json Format Rules Every Developer Should Know
📖 Bu rehber ToolPazar ekibi tarafından hazırlanmıştır. Tüm araçlarımız ücretsiz ve reklamsızdır.
RFC 8259: the strict spec
JSON is the lingua franca of web APIs — and almost every developer learns it by osmosis from copy-pasted examples rather than the spec. That works until it doesn’t: a trailing comma, a single quote, or an unescaped backslash breaks a production payload at 2 AM, and the parser error message is unhelpful.
The 6 hard rules
This is a complete reference for the rules of strict JSON (RFC 8259), the relaxed variants you’ll encounter (JSON5, JSONC), the encoding edges that catch people, and the patterns for handling huge documents, schemas, and security risks. It’s organized as a working reference — jump to what you need.
String escaping rules
JSON was originally specified by Douglas Crockford in 2002 (RFC 4627), updated to RFC 7159 in 2014, and finalized as RFC 8259 in 2017 (also published as ECMA-404 and ISO/IEC 21778). RFC 8259 is the current authoritative spec; if your tool claims “JSON support” without specifying a variant, it should mean RFC 8259. The spec is short — about 16 pages including examples — and worth reading once.
Number representation gotchas
The full list of escapes inside a JSON string:
JSON5 and JSONC: when to use each
JSON numbers are 64-bit floats by spec (IEEE 754 doubles). Implications:
Top 10 parser errors and fixes
Two relaxed variants are common in tooling but never in APIs:
JSON Schema: validation beyond syntax
Example schema for a user object:
Handling huge JSON (streaming)
RFC 8259 requires UTF-8 encoding (with optional UTF-16 / UTF-32 in older RFC 7159). Network JSON should always be UTF-8 without BOM.
UTF-8, BOMs, and binary data
The six rules cover almost all parse errors you’ll encounter. The schema validation pattern (Ajv, Zod, JSON Schema) catches the rest at the contract level so bugs surface early. For huge documents, switch to streaming parsers or NDJSON. For binary data, Base64-encode or send out-of-band. Always validate untrusted JSON before merging into objects (prototype pollution).