> ## Content Index
> Fetch the complete content index at: https://new-blog.dougals.me/llms.txt
> Use this file to discover other available public pages before exploring further.

# JSON
- URL: https://new-blog.dougals.me/json/
- Published: 2025-09-20T13:51:19.000Z
- Updated: 2025-09-20T13:51:19.000Z
- Author: Dougie Richardson
- Tags: Coding, Python, Howto, JSON, #Migrated-1789219936886, #wp, #wp-post, #Import 2026-09-12 13:32

Following on from this [post](https://blog.dougals.me/coding/interact-with-api-in-python/?ref=new-blog.dougals.me), I thought it might be good to think about JavaScript Object Notation (JSON).

Despite its name, [JSON](https://www.json.org/json-en.html?ref=new-blog.dougals.me) has evolved to be agnostic and is arguably the standard for exchanging information because its human readable and easy for computers to parse.

JSON is two things: a collection of key value pairs, and an ordered list of values. The former is easily represented with objects, dictionaries, etc. and he latter with arrays, lists, or sequences.

- Values are string, number, object, array, true/false, or null surrounded by white-space.
- Objects are unordered key-value pairs, represented by colon separated key-value pairs and wrapped in curly brackets.
- Arrays are comma separated ordered collections wrapped in square brackets.
- Comments, trailing commas, and single quoted strings are not supported.

```json
{
    "name" : "Dougie",
    "languages" : [ "python", "java" ]
}
```

Python has a standard module, *json*, making it simple to convert Python and JSON data types. Serialisation is converting to JSON, but take care with de-serialisation as it is not *quite* the reverse. Not all Python data types can be converted to JSON values, so objects may not retain their original type.

This can introduce subtle problems when serialising and de-serialising:

- JSON requires keys to be strings, so where another type is given during serialisation, it will be a string when de-serialised.
- True serialises to true, and None serialises to null. The reverse is also true.
- Tuple are serialised as arrays, there is no way to tell when de-serialising so you will get a list.

Serialising is done by dumping:

```python
json.dumps(python_data)
```

Deserialising JSON is done by loading:

```python
json.loads(json_data)
```

JSON is human readable but can be made easier to read by specifying indentation level:

```python
json.dumps(sample_json, indent=2)
```