JSON
What is JSON?
JSON (JavaScript Object Notation) is a lightweight data-interchange format that is easy for humans to read and write, and 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.
Short History
JSON was initially created by Douglas Crockford in the early 2000s as a simpler alternative to XML for various web services. Its adoption was quick, given it naturally fit into JavaScript, which was rapidly gaining popularity for web development. JSON has since become a universal standard, used for data interchange between servers and web applications, as well as configurations and data storage among many other uses.
Primary Usage
The primary usage of JSON is to transmit data between a server and a web application or within application layers. Its simplicity and effectiveness in structuring data have made it extensively used in programming environments beyond JavaScript, including services, mobile apps, and configuration files.
JSON Syntax
JSON syntax is derived from JavaScript object notation syntax, but it's text-only, making it highly interchangeable. JSON structures data in name/value pairs and ordered lists of values. Here are the basic rules:
Data is in name/value pairs
Data is separated by commas
Curly braces hold objects
Square brackets hold arrays
Basic Types
String: A sequence of zero or more Unicode characters, wrapped in double quotes.
Number: A signed decimal number that may contain a fractional part and may use exponential E notation, but cannot include non-numbers like NaN.
Boolean: True or false.
Array: An ordered collection of values, enclosed in square brackets.
Object: An unordered collection of key/value pairs, enclosed in curly brackets.
Null: An empty value, using the word null.
Example of JSON:
Using JSON with JavaScript
To use JSON data in JavaScript, one can convert JSON into a JavaScript object with JSON.parse()
, and convert a JavaScript object back into JSON with JSON.stringify()
.
Last updated
Was this helpful?