Skip to content

JSON in Python

JSON is made up of "Key-Value Pairs". JSON supports a few data-types.

Data Types

String

{"key": "value"}

Number

{"number": 1234}

Boolean

{"boolean": True}

JSON Object

{"json_object": {"key": "value", "number": 1234, "boolean": False}}

Array

{"array": ["item1", "item2", "item3"]}

Null

{"key": null}

JSON Library (Python)

import json

# some JSON:
x =  '{ "name":"John", "age":30, "city":"New York"}'

# parse x:
y = json.loads(x)

# the result is a Python dictionary:
print(y["age"])