# JSON Introduction

JSON (JavaScript Object Notation) is a text-based, language independent, open standard for data interchange. One of its advanages is that it is human-readable.

An alternative to XML, JSON is primarily used to transmit data between a server and web application.

JSON is built upon two types of structures:

- A collection of name/value pairs
- An ordered list of values

The main JSON website can be found at www.json.org.

Note: Source code to parse and generate JSON data is readily available for a large variety of programming languages.

# JSON Files

JSON files typically have a file extension of ".json".

# MIME Type

The MIME type for JSON text is "application/json".

# JSON vs. XML

- JSON is much simpler than XML with a much smaller grammar
- JSON is much easier for humans to read than XML
- JSON and XML are both open standards
- JSON is data-oriented and can be more easily mapped to object-oriented systems
- JSON and XML both use Unicode for easier internationalization
- JSON support is already built into JavaScript and Python. Since it is a simpler notation, much less code is required for support in other languages
- JSON is better for data exchange. XML is better for document exchange

# Data vs. Document

When using Ajax, JSON and XML approach data differently:

## The Document Approach (XML):

1. Retrieve an XML document
2. Loop through the document, extracting the values
3. Do something with the values

## The Data Approach (JSON):

1. Retrieve the JSON string
2. 'eval' the string

# JSON Statistics

- Originally specified by Douglas Crockford in 2001
- Defined in RFC 4627