Definition:
JSON, short for JavaScript Object Notation, is a text format used to represent and exchange structured data. It organizes information through objects, arrays, and simple values, using a compact syntax that many programming languages and software applications can read and generate.
Although its name comes from JavaScript, JSON is not a programming language. It does not contain instructions or execute operations: it describes data. It should also be distinguished from a database, which may store JSON documents but provides additional functions to query, update, and manage information.
JSON syntax
A JSON document follows a defined syntax. Objects are enclosed in braces and contain pairs made up of a name and a value. Arrays are enclosed in brackets and preserve an ordered sequence of values. In both structures, commas separate elements and a colon separates each name from its value.
The main rules are:
- Quoted names: every member of an object uses a string name enclosed in double quotation marks.
- Accepted values: values can be strings, numbers, objects, arrays, or the literals
true,false, andnull. - Double quotes: strings must be enclosed in double quotation marks rather than single quotation marks.
- No trailing comma: the final member of an object or element of an array has no additional comma.
- Optional whitespace: spaces, tabs, and line breaks can improve readability without changing meaning outside strings.
- No comments: the standard syntax does not include comments, functions, or values such as
undefined.
These restrictions allow the same document to be interpreted consistently by different systems. In open exchanges between applications, JSON text is normally encoded in UTF-8.
JSON data types
JSON supports a limited set of value types. A string represents text; a number represents a quantity without formally distinguishing integers from decimals; booleans express true or false; and null represents a null value. Objects group named members, while arrays collect values in order.
The format does not include specific types for dates, images, or binary files. A date is commonly transmitted as a string under an agreed convention, while binary data requires another representation or a separate channel. The recipient needs to understand this data contract to interpret the content beyond its syntax.
Duplicate names within the same object should also be avoided. Some parsers keep the last value, others retain the first, and others report an error. A document may therefore be syntactically valid and still produce different results if its structure relies on that ambiguity.
Uses of JSON
JSON is frequently used to carry information between a client and a server. Many APIs use it in requests and responses sent over HTTP because it is relatively compact and parsers are available in most development environments.
Its common uses include:
- Web exchange: responses from services and applications connected through an API.
- Configuration files: settings loaded by an application at startup or during execution.
- System messages: events, tasks, or states passed between components in an architecture.
- Document storage: records stored as documents when the selected system supports JSON structures.
It is not always the right option. Compared with XML, JSON has no native features such as attributes, namespaces, or comments. For large tabular datasets, it may be more repetitive than a row-oriented format. The choice depends on the structure, validation requirements, and systems that will consume the data.
JSON and JavaScript
JSON syntax is inspired by JavaScript object notation, but the two concepts are not equivalent. JSON is language independent and can be processed in Python, PHP, Java, R, and many other environments. Its grammar is also more limited than that of an object written directly in JavaScript code.
The notation was derived from ECMAScript syntax, but its rules are described independently in RFC 8259 and ECMA-404. This technical standardization allows JSON to be implemented without depending on JavaScript.
In JavaScript, JSON.parse() converts valid JSON text into a language value, while JSON.stringify() performs the reverse operation on compatible data. Parsing text with a dedicated parser is safer and more predictable than treating it as executable code.
A valid example is:
{
"books": [
{
"title": "The Lord of the Rings",
"author": "J. R. R. Tolkien",
"published": 1954,
"available": true
},
{
"title": "1984",
"author": "George Orwell",
"published": 1949,
"available": false
}
]
}
The root value is an object with a books property. Its value is an array containing two objects. Each book combines strings, a number, and a boolean, showing how JSON can represent a nested structure without defining behavior.
JSON validation
Validating JSON first means checking that the text follows the grammar. A parser will detect issues such as incorrect quotation marks, unescaped characters, trailing commas, or unclosed braces. This syntax validation does not confirm that the names, types, and required fields match what an application expects.
When structural validation is required, a schema or rules in the receiving system can be used. A REST API, for example, may require a particular property to be a string, reject unknown fields, or restrict certain values.
Before processing external data, systems should limit its size, check its types, and handle parser errors. JSON supports interoperability, but it does not by itself guarantee data quality, authenticity, or security.
