JSON Format Specification & Converter Info
JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language Standard ECMA-262 3rd Edition - December 1999.
Introduction
JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language.
Key Features
- Lightweight: JSON has a small footprint, making it ideal for data transmission over networks.
- Human-Readable: The syntax is simple and easy to understand.
- Language Independent: Supported by virtually all modern programming languages.
- Self-Describing: The structure of the data is evident from the format itself.
Syntax
JSON is built on two structures:
- A collection of name/value pairs. In various languages, this is realized as an object, record, struct, dictionary, hash table, keyed list, or associative array.
- An ordered list of values. In most languages, this is realized as an array, vector, list, or sequence.
Example
{
"name": "John Doe",
"age": 30,
"isStudent": false,
"courses": ["Math", "Computer Science"],
"address": {
"street": "123 Main St",
"city": "Anytown"
}
}Data Types
JSON supports the following data types:
- String: A sequence of Unicode characters, enclosed in double quotes.
- Number: Integer or floating-point numbers.
- Boolean:
trueorfalse. - Null: Represents an empty value, written as
null. - Object: An unordered collection of key/value pairs, enclosed in curly braces
{}. - Array: An ordered list of values, enclosed in square brackets
[].
Use Cases
- Web APIs: The de facto standard for data exchange in RESTful APIs.
- Configuration Files: Used for configuring applications (e.g.,
package.json,tsconfig.json). - Data Storage: NoSQL databases like MongoDB use JSON-like formats (BSON) for storage.
Related Formats
Compare JSON with other data formats:
- TOON (Token-Oriented Object Notation) - Optimized for LLMs to save tokens.
- YAML - Often used for configuration files where human readability is paramount.
- XML - A markup language with a strict syntax, often used in enterprise systems.
- TOML - A minimal configuration file format.