jsonobject is a Python library for handling deeply nested JSON objects as well-schema'd Python objects. It provides a declarative way to define data models for JSON structures, facilitating easy serialization and deserialization between Python objects and JSON. Maintained by Dimagi, it is currently at version 2.3.1 and typically follows an active release cadence.
Install & Compatibility
Where this runs
tested against v2.3.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.041s · 26.4MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 1.7s · import 0.038s · 29MB
26MB installed
● package 26MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
from jsonobject import JsonObject
from jsonobject import StringProperty
from jsonobject import IntegerProperty
from jsonobject import BooleanProperty
from jsonobject import DateTimeProperty
from jsonobject import ListProperty
from jsonobject import DictProperty
Define a `JsonObject` subclass with various `Property` types, instantiate objects, and serialize them to JSON. Also demonstrates deserialization from a dictionary.
import datetime
from jsonobject import JsonObject, StringProperty, BooleanProperty, DateTimeProperty, ListProperty
class User(JsonObject):
username = StringProperty(required=True)
name = StringProperty()
active = BooleanProperty(default=False)
date_joined = DateTimeProperty()
tags = ListProperty(str)
# Create an object
user1 = User(
name='Jane Doe',
username='janedoe',
date_joined=datetime.datetime.utcnow(),
tags=['developer', 'python']
)
print(f"User object: {user1}")
print(f"User to JSON: {user1.to_json()}")
# Create from existing JSON
json_data = {
'username': 'alice',
'name': 'Alice Smith',
'active': True,
'date_joined': '2023-01-15T10:30:00Z',
'tags': ['tester']
}
user2 = User(json_data)
print(f"User from JSON: {user2}")
print(f"Is user2 active? {user2.active}")
Upgrade
Version history
Breaking-change detection hasn't run for this library yet.
Audit
Security & dependencies
CVE tracking and dependency tree are planned for a later release.