> For the complete documentation index, see [llms.txt](https://university-west.gitbook.io/programming-paradigms/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://university-west.gitbook.io/programming-paradigms/web-development/json.md).

# 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

1. **String**: A sequence of zero or more Unicode characters, wrapped in double quotes.
2. **Number**: A signed decimal number that may contain a fractional part and may use exponential E notation, but cannot include non-numbers like NaN.
3. **Boolean**: True or false.
4. **Array**: An ordered collection of values, enclosed in square brackets.
5. **Object**: An unordered collection of key/value pairs, enclosed in curly brackets.
6. **Null**: An empty value, using the word null.

#### Example of JSON:

```json
{
  "name": "John Doe",
  "age": 30,
  "isAdmin": false,
  "courses": ["JavaScript", "HTML", "CSS"],
  "address": {
    "street": "123 Main St",
    "city": "Anytown"
  }
}
```

#### 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()`.

```javascript
// JSON string
var jsonString = '{"name": "John Doe", "age": 30}';

// Converting JSON string to JavaScript object
var jsObject = JSON.parse(jsonString);

// Accessing the data
console.log(jsObject.name); // John Doe

// Converting JavaScript object to JSON string
var newJsonString = JSON.stringify(jsObject);

console.log(newJsonString); // {"name":"John Doe","age":30}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://university-west.gitbook.io/programming-paradigms/web-development/json.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
