Simplejson

3.20.2 · active · verified Sat Mar 28

Simplejson is a fast, extensible, and standards-compliant JSON encoder/decoder for Python. It's often used as a drop-in replacement for Python's built-in `json` module, offering a C extension for improved performance and additional features. The library is actively maintained, with the current stable version being 3.20.2, and releases occur several times a year.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates encoding a Python dictionary into a formatted JSON string using `simplejson.dumps` and then decoding it back into a Python object using `simplejson.loads`.

import simplejson

data = {'name': 'Alice', 'age': 30, 'is_student': False, 'courses': ['Math', 'Science']}

# Encode Python object to JSON string
json_string = simplejson.dumps(data, indent=4)
print('Encoded JSON:')
print(json_string)

# Decode JSON string to Python object
decoded_data = simplejson.loads(json_string)
print('\nDecoded Data:')
print(decoded_data)
print(f"Accessing a value: {decoded_data['name']}")

view raw JSON →