link: Web Data Handling and Formats
JSON (JavaScript Object Notation)
Overview
JSON (JavaScript Object Notation) is a lightweight, text-based, language-independent data interchange format, derived from JavaScript but used by many programming languages. JSON is easy for humans to read and write, and easy for machines to parse and generate.
Key Features of JSON
Key Features
- Text-based: JSON is purely text, which can be read and parsed by a wide variety of programming languages.
- Human-readable: The format is self-describing and easy to understand.
- Lightweight: JSON structures are compact, which makes them ideal for network transmissions.
- Language-Independent: Though derived from JavaScript, JSON is supported natively or through libraries in most major programming languages.
JSON Syntax
JSON Syntax
JSON is built on two structures:
- Objects: 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.
- Arrays: An ordered list of values. In most languages, this is realized as an array, vector, list, or sequence.
Here is a basic example of JSON:
Data Types Supported:
- Strings: Must be written in double quotes.
- Numbers: Integer or floating-point.
- Objects: An unordered set of name/value pairs.
- Arrays: An ordered collection of values.
- Booleans:
true
orfalse
.- Null: An empty value, written as
null
JSON vs XML
Comparison
Link to original
Feature JSON XML Verbosity Lightweight and less verbose More verbose, leading to potentially larger files Readability High readability and ease of use Readable but can be cumbersome due to verbosity Complexity Lower complexity, easier to parse Higher complexity, robust parsing required Data Structures Ideal for array and key-value pairs Better for complex hierarchical data structures Metadata Support Limited metadata capabilities Extensive metadata support through attributes Scalability Highly scalable for web and mobile applications Scalable but better suited for enterprise systems Security Basic security suitable for web data Advanced security features like support for XML Signature Interoperability High with web technologies High across various software and systems Use Cases APIs, web configurations, client-server apps Complex document-based applications, enterprise data exchange Encoding Support Unicode support directly Extensive support for various encodings