2024-02-08T17:35:49
Status: #moc
Tags: #json
Links: [[home]] | [[Technology]] | [[Standards]]
# JSON (JavaScript Object Notation)
## Introduction
JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write, and easy for machines to parse and generate. JSON is based on a subset of the JavaScript Programming Language Standard ECMA-262 3rd Edition - December 1999. Despite its origin, JSON is language-independent, making it a popular choice for data interchange on the web.
![[afalk42_An_illustration_for_a_knowledge_base_article_on_JSON_th_a30435e4-7939-4ae7-86b5-93f0d04ed7d7.png]]
## Structure
JSON is built on two structures:
1. **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.
2. **An ordered list of values**: In most languages, this is realized as an array, vector, list, or sequence.
## Basic Types
JSON supports various data types which are common in most programming languages. These include:
- **Number**: A double-precision floating-point format in JavaScript, which can include numbers with or without a fractional part.
- **String**: A sequence of zero or more Unicode characters. Strings are enclosed in double quotes (").
- **Boolean**: True or false values.
- **Array**: An ordered list of zero or more values, each of which can be of any type. Arrays are enclosed in square brackets ([]).
- **Object**: A collection of key/value pairs where the keys are strings and the values can be any of these types. Objects are enclosed in curly braces ({}).
- **null**: Represents an empty or non-existent value.
## Examples
Here is a simple JSON object example as text:
```json
{
"name": "John Doe",
"age": 30,
"isEmployed": true,
"address": {
"street": "123 Main St",
"city": "Anytown",
"zip": "12345"
},
"phoneNumbers": ["123-456-7890", "987-654-3210"]
}
```
And another example of JSON displayed in a grid view for easier editing (in [[XMLSpy]]):
![[Pasted image 20240213174701.png]]
## Usage in Programming
JSON is widely used in web development and other types of programming. It serves as a method of exchanging data between a client (such as a web browser or mobile app) and a server. Most programming languages have built-in or external libraries to parse JSON data to native data structures and vice versa.
## Advantages
- **Lightweight**: JSON format is relatively simple and uses less bandwidth than other structured data formats, such as SGML, HTML, and XML.
- **Easy to Read and Write**: Its syntax is straightforward, making it human-readable and writable.
- **Language Independent**: JSON can be used with most modern programming languages.
## Disadvantages
- **Only a data format**: contrary to XML, JSON does not have corresponding processing languages, such as XPath, XSLT, and XQuery. However, some advanced tools, such as [[XMLSpy]], allow you to [apply XPath and XQuery to JSON data](https://www.altova.com/json-tools#json-xquery-xslt) in addition to XML data.
## JSON Tools
[[Altova]] provides a series of focused [JSON functionality](https://www.altova.com/json-tools) across its popular Developer Tools portfolio:
- The XMLSpy [JSON editor](https://www.altova.com/xmlspy-xml-editor/json_editor) supports JSON, JSON5, JSON Lines, and JSON with Comments.
- The [JSON Schema editor](https://www.altova.com/xmlspy-xml-editor/json_schema_editor) in XMLSpy allows visual, drag and drop editing with intelligent entry helpers. This makes JSON Schema development much easier, compared to working in a text only view.
- JSON tools in XMLSpy make it easy to take advantage of functionality added to XPath/XQuery 3.1 that provides an elegant, standardized way to query and transform JSON data using these familiar languages.
- When more complex or recurrent [JSON data mapping](https://www.altova.com/mapforce/json-mapping) is required, MapForce is the tool for the job. An any-to-any data transformation tool, MapForce supports JSON as both an input and output data format, allowing you to map JSON to and from:
- [[XML]]
- [[Database]]s
- Flat files
- [[EDI]]
- Protobuf
- [[XBRL]]
- Web services
- Excel
- The advantages of JSON’s small footprint make it well suited as a back end data format for mobile apps, where it’s important to transfer the smallest amount of data possible to deliver optimal performance. When building your mobile app in [[MobileTogether]], you can utilize JSON either loaded directly from a file or consumed via a REST web service or via an HTTP or FTP request.
## Conclusion
JSON's simplicity, readability, and usability across multiple languages have made it an essential tool for web developers and programmers worldwide. Its role in the exchange of data across different systems and platforms accentuates its importance in today's interconnected technology landscape.
## References
- http://www.json.org/
- https://www.altova.com/json-tools
- https://www.altova.com/xmlspy-xml-editor/json_editor