JSON (JavaScript Object Notation) is a serializable data interchange format intended to be machine and human readable. Do not use this tag for native JavaScript objects or JavaScript object literals. Before you ask a question, validate your JSON using a JSON validator such as JSONLint (https://jsonlint.com).
JSON (JavaScript Object Notation) is a serializable data interchange format intended to be machine- and human-readable.
JSON is defined by RFC 7159 which is completely language independent, but it uses conventions familiar to programmers of the C-family of languages, including c, c++, c#, java, javascript, perl, python, and many others. These properties make JSON an ideal data-interchange language to use with RESTful APIs or ajax. It is often used instead of xml because of its lightweight and compact structure.
Many programming languages provide methods for parsing a JSON-formatted text string into a native object and vice versa. For example, JavaScript in modern browsers and other environments includes the methods JSON.parse() and JSON.stringify().
The JSON format is based on two types of structures:
Collection of name/value pairs
{"name1":"value1", "name2":"value2"}
An ordered list of values (more commonly referred to as an array)
["value1", "value2"]
JSON defines six types of values: null, numbers, strings, booleans, arrays and objects. With regard to objects, the order of members is not significant, and the behavior of a JSON parser when duplicate member names are encountered is undefined.
Note that JSON is not the same thing as JavaScript object literals. Rather, JSON is a common format to serialize from and deserialize to objects in most languages. For more information, see There is no such thing as a JSON object in JavaScript.
Shortly after it was created, JSON validation was added following the description set out by Douglas Crockford of json.org in RFC 4627. It has since been expanded to also validate both current competing JSON standards RFC 7159 and ECMA-404.
Advantages
- JSON is a lightweight data-interchange format (no markup bloat)
- JSON is language independent.
- JSON is "self-describing" and easy to understand.
- JSON can be natively understood by JavaScript parsers, including node.js
JSON libraries
- Java: JSR 353 (JSONP), FasterXML Jackson, Google Gson, JSON-Java, or jsoniter
- JavaScript: json2.js (only needed in old browsers without native JSON support)
- Ruby: JSON implementation for Ruby
- C#: JSON.Net
- Python 2: JSON encoder and decoder
- Python 3: JSON encoder and decoder
- PHP: JSON extension for PHP
- C:
- Jansson – C library for encoding, decoding and manipulating JSON.
- jsmn – Minimalistic JSON parser.
- json-c – Library for working with JSON.
- parson – Lightweight JSON library written in C.
- WJElement – Advanced JSON manipulation library, with support for JSON Schema.
- YAJL – Fast C JSON streaming parser library.
- cJSON – Ultralightweight JSON parser
- C++:
- nlohmann/json – JSON for Modern C++
- RapidJSON – Fast JSON parser/generator with SAM/DOM API
- taoJSON – header-only JSON library
- Scala: play-json, json4s, spray-json, and much more as elaborated at What JSON library to use in Scala?
Browser Addons
Useful links
- Wikipedia page
- JSON Example
- JSON: What It Is, How It Works, & How to Use It
- JSON on Mozilla Developer Network
- JSONLint
- JSON-Introduction By Microsoft
- Get Started With JSON (Introduction at Wired)
- JSON library for old browsers (IE8 and below)
- FAQ on Stack Overflow
- jq (Command line JSON processor)
- JSON Formatter & Validator
- XML and JSON -- Advantages and Disadvantages?
Books
- Beginning JSON
- Introduction to JavaScript Object Notation A To-the-Point Guide to JSON
- JavaScript JSON Cookbook
- JavaScript and JSON Essentials