JSON Data Interchange Format: Syntax, Standards, and Engineering Practices
This article explains JSON's definition and standardization history, its six core data types, common syntax pitfalls, JSON Schema-based validation, and practical engineering guidelines for building reliable data exchange between systems.
What Is JSON?
JSON (JavaScript Object Notation) is a lightweight, open-standard data interchange format. It is designed to make data easy for humans to read and write while remaining easy for machines to parse and generate. JSON uses a text format that is completely independent of programming languages, while borrowing common conventions for numbers, strings, and structures from the C language family, including JavaScript, C, C++, and Java. This allows structured data to be exchanged losslessly across different languages.
With its concise syntax, strong readability, and low parsing cost, JSON has become one of the most widely used data interchange formats on the Internet. It is commonly used for communication between web frontends and backend services, request and response bodies in RESTful APIs, configuration file management, and structured log output. JSON files typically use the .json extension and the application/json MIME type.
The Standardization of JSON
JSON originally emerged as a subset of ECMAScript object literal syntax, but it was explicitly defined as a data format independent of any programming language and does not rely on a JavaScript runtime. Its standardization process can be summarized as follows:
- Early stage: The syntax conventions of JSON were promoted by its designer in the community and gradually gained support from parsers in major programming languages.
- 2014: The IETF published RFC 7159, which systematically specified JSON syntax and usage rules in a Request for Comments document for the first time.
- 2017: RFC 8259 was published and replaced RFC 7159, with minor adjustments and refinements to the standard. In the same year, Ecma International published ECMA-404, which complements the IETF specification and jointly defines JSON syntax.
Currently, RFC 8259 and ECMA-404 are the authoritative standards describing JSON syntax. Related specification information is available in public documents published by the standards organizations.
Core JSON Syntax
JSON supports only the following six data types, with clear and unambiguous rules:
- Object: An unordered collection of key-value pairs enclosed in curly braces. Keys must be strings wrapped in double quotes, and key-value pairs are separated by commas. Example:
{"name": "Alice", "age": 25}. - Array: An ordered list of values enclosed in square brackets, with elements separated by commas. Example:
[1, 2, 3]. - String: Must use double quotes and supports backslash escapes such as
\",\n,\t, and\u4E2D. - Number: Supports integers and floating-point numbers, including scientific notation. Octal and hexadecimal literals are not supported, and special values such as
NaNandInfinityare not allowed. - Boolean:
trueorfalse, and both must be lowercase. - Null: Represents “no value” and must be lowercase.
Example:
{"user": {"id": 1001,"name": "Bob","tags": ["developer", "tester"],"active": true,"profile": null}}
Common JSON Pitfalls
Although JSON syntax is simple, the following issues still require attention in practice:
- Keys must use double quotes: Keys with single quotes or no quotes are invalid in JSON. This differs from JavaScript object literals.
- Comments are not supported:
//or/* */comments cannot appear in JSON files. In configuration scenarios that require comments, some teams use extended formats with comment support or compensate through conventional fields such as"_comment". - Trailing commas are forbidden: A comma cannot appear after the last element of an array or object; otherwise, parsing will fail.
- Encoding conventions: JSON text uses UTF-8 by default, and parsers should correctly handle character set declarations.
- Large-number precision: Integers beyond common floating-point precision, such as IDs larger than 64 bits, may lose precision in some runtimes. In engineering practice, large numbers are often transmitted as strings.
JSON Schema: Structure Description and Validation
When JSON is used as an API contract or configuration specification, syntax validation alone is not enough to guarantee data correctness. JSON Schema is a technical standard for describing and validating the structure of JSON documents. A JSON Schema is itself a valid JSON document and can declare:
- Type constraints for fields, such as
string,number, andobject; - Required and optional fields;
- Detailed rules such as string length, numeric ranges, and enumerated values;
- Constraints on subobjects in nested structures.
Example:
{"type": "object","required": ["id", "name"],"properties": {"id": { "type": "integer" },"name": { "type": "string", "minLength": 1 },"tags": { "type": "array", "items": { "type": "string" } }}}
With Schema validation, servers can quickly reject noncompliant request data at the entry point, and clients can generate documentation or forms based on the Schema. This significantly improves API collaboration efficiency.
Engineering Practice Recommendations
- Use consistent naming conventions: Teams should agree on a field naming style, such as camelCase or snake_case, to avoid mapping costs caused by frontend-backend inconsistency.
- Use standard libraries or mature parsers: Mainstream programming languages provide built-in or standard JSON parsing capabilities. Standard solutions should be preferred to avoid security vulnerabilities introduced by handwritten parsing logic. For example, stack overflow caused by deeply nested data can be mitigated by limiting parsing depth.
- Follow conventions in API design: In RESTful APIs, request and response bodies should explicitly declare
Content-Type: application/json, and error information should also be returned in a structured form for uniform handling. - Optimize data size: In bandwidth-sensitive scenarios, insignificant whitespace can be removed, field names can be shortened, or general compression methods can be combined to further reduce bandwidth overhead.
Conclusion
With its minimal syntax design and strict standardization, JSON solves the core problem of data exchange between heterogeneous systems. Understanding its syntax rules, standardization background, and JSON Schema validation mechanisms is a foundational skill for every developer building reliable web services. In real engineering work, following specifications, agreeing on conventions first, and making good use of validation tools are essential to fully realize the value of this data format.
