Registry / serialization / jsonobject

jsonobject

JSON →
library2.3.1pypypi✓ verified 35d ago

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.

serializationdata
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
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.041s · 26.4MB
glibc
py 3.103.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}")
Debug
Known footguns
breakingVersion 2.0.0 changed the behavior of `ListProperty` when an iterable is passed as its value type. Previously, it might have raised `BadValueError`; now, it returns a plain Python list. This was considered a fix for unintuitive behavior but could be breaking if previous error handling was relied upon.
breakingVersion 1.0.0 officially dropped support for Python 2.7, 3.5, and 3.6. Using `jsonobject` 1.0.0 or higher with these Python versions will result in compatibility errors.
gotchaWhen defining `Property` types, be cautious with mutable default values (e.g., `ListProperty(default=[])` or `DictProperty(default={})`). If a mutable object is used as a default, all instances of the `JsonObject` class will share the *same* mutable object, leading to unexpected side effects when one instance modifies it.
gotchaThe `jsonobject` library provides schema-driven object mapping for JSON. It is distinct from Python's built-in `json` module, which offers basic JSON encoding/decoding, and also distinct from Java libraries often named `JSONObject`. Avoid confusing their APIs or expecting direct interoperability without explicit conversion.
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.

Agent activity
13 hits · last 30 days
gptbot
4
ahrefsbot
4
bytedance
3
dotbot
1
script
1
Resources