JSON
JSON
JavaScript Object Notation, commonly abbreviated as JSON, is a standard data interchange format used to transmit and store data as text. It is functionally very similar to other serialization formats such as XML.
The notation of JSON is very similar to that of data types in JavaScript, hence the name.
How is data encoded in JSON?
JSON has two top-level elements, an object (which consists of key-value pairs) and an array (an ordered set of values). Keys can only be strings, while values can be one of the following types:
- object: a collection of key-value pairs, enclosed in { }
- array: an ordered list of values, enclosed in [ ]
- string: an ordered sequence of text, enclosed in " "
- number: a numeric value expressed in decimal, with exponent notation allowed
- boolean: true or false
- null: lack of a value
JSON can describe nested and complex data structures since both objects and arrays can contain values that might be objects or arrays.
What are the shortcomings of JSON?
JSON's primary intent was machine-parsable, so it uses punctuation for enclosing literals and delimitation. It also lacks comments, making it quite unfit for manual reading/writing. YAML is another data format that uses reduced punctuation, adds comments, and makes it more suitable for manual editing. It is a strict superset of JSON.
Example
Write clean and secure code with DeepSource
Powerful static analysis that takes 5 minutes to set up and helps you fix code health and security problems on every pull request.