JavaScript Object Notation (.json)

RFC 标准

JavaScript Object Notation (JSON) is a lightweight, human-readable text format for data interchange, completely language-independent and universally used for web APIs.

将 JSON 转换为 HTML

免费的浏览器端 JSON 转 HTML 转换器。在您的设备上即时转换文件。

在线压缩 JSON

100% 浏览器本地私密压缩 — 文件永不离开您的设备

检查与元数据

操作系统和文件分析器通过检查开头的二进制字节序列来识别 JSON 文件:

选择或拖放文件

选择或将文件拖放到此处

100% 浏览器端私密转换 - 文件绝不会离开您的设备

或粘贴 Ctrl+V
零网络传输隐私保证: 上传至外部服务器的数据为 0 字节。所有处理均在您的浏览器沙箱中本地完成。

字节级文件头签名 (Magic Bytes)

操作系统和文件分析器通过检查开头的二进制字节序列来识别 JSON 文件:

十六进制签名 (偏移量 0):

7B or 5B

ASCII 表示形式: { or [

标准化: RFC 8259 / ECMA-404 / ISO/IEC 21778

技术规格

容器架构Lightweight, text-based, language-independent data interchange format
压缩方式Gzip / Brotli / Zstandard text compression (typically achieves 80%-90% ratio)
字节序UTF-8 encoded Unicode (no Byte Order Mark / BOM recommended)
色彩空间Not applicable
通道与结构Six basic data types: object, array, string, number, boolean, null
最大尺寸Unbounded; limited only by parser memory and maximum string length
透明度Not applicable
流式传输与渐进式加载NDJSON (Newline Delimited JSON) / JSON Lines enables progressive stream processing

技术对比矩阵:JSON 对比同类产品

技术属性JSON (当前)YAMLXMLProtocol Buffers
Syntax ComplexityMinimal (6 types, strict syntax)High (indentation-based, complex spec)High (verbose closing tags, namespaces)Schema-defined binary wire format
Parsing PerformanceExtremely fast in all modern languagesSlow (complex indentation parsing)Moderate to slow (heavy DOM construction)Ultra-fast (zero-copy binary deserialization)
Comments SupportedNo (deliberately excluded to prevent metadata creep)Yes (# comments)Yes (<!-- comments -->)Yes in .proto files
Network Payload SizeCompact text (very high gzip ratio)Compact textVerbose text (heavy tag repetition)Ultra-compact binary

常见损坏模式与十六进制恢复指南

⚠️ SyntaxError: Unexpected token , in JSON at position X.

根本原因: Trailing comma after the last item in an array or object, which is strictly illegal in RFC 8259 JSON.

恢复方法: Remove trailing commas from object keys and array entries before passing to JSON.parse().

⚠️ SyntaxError: Unexpected token ' in JSON.

根本原因: Strings or keys enclosed in single quotes ('') instead of double quotes ("").

恢复方法: Replace all single-quoted strings and keys with standard double-quoted strings.

安全分析与解析器攻击向量

JSON is text-only and safe from direct code execution, but parsing untrusted JSON can lead to Prototype Pollution, ReDoS, or memory exhaustion.

已知攻击向量

  • Prototype Pollution: Keys named '__proto__' or 'constructor' modifying Object.prototype in JavaScript applications.
  • Stack overflow denial of service via deeply nested JSON structures (e.g. 10,000 opening brackets).
  • Loss of numeric precision: JavaScript numbers larger than 2^53 - 1 (9,007,199,254,740,991) silently lose precision.

防御性最佳实践: Never evaluate JSON with eval(). Use JSON.parse() and sanitize '__proto__' properties in recursive object merge functions.

历史渊源与里程碑

2017RFC 8259 standardizes UTF-8 as the sole mandatory character encoding for JSON.
2013ECMA-404 defines the universal JSON syntax standard.
2001Douglas Crockford specifies JSON to enable stateless browser-to-server data communication.

核心优势与特点

  • Human-readable, self-describing, and concise text structure.
  • Native parsing support built into JavaScript engines (JSON.parse) and every major programming language.
  • Strict specification prevents arbitrary code execution.

技术局限与劣势

  • No support for comments, trailing commas, or circular object references.
  • No native binary types (binary data must be base64-encoded, inflating size by 33%).
  • Inefficient serialization compared to binary formats like Protocol Buffers or MessagePack.

趣味技术冷知识

  • Douglas Crockford added the software license clause 'The Software shall be used for Good, not Evil' to the original JSMin JSON tools.
  • JSON is a strict subset of JavaScript syntax, but until ES2019, raw unescaped U+2028 and U+2029 characters were valid in JSON but invalid in JavaScript strings.

常见技术问题

Why doesn't JSON allow comments?

Douglas Crockford deliberately excluded comments from the JSON specification to prevent developers from putting parsing instructions or environment-dependent configuration pragmas into data feeds, preserving universal interoperability.

How do you store 64-bit integers in JSON without losing precision?

JavaScript's native Number type is an IEEE 754 double-precision float, which only supports integers up to 2^53 - 1 precisely. 64-bit integers (like database IDs or timestamps) must be serialized as strings (e.g. '1234567890123456789') in JSON.