Stdlib function to jsonify almost any Python object recursively
Project description
jsonify-objects
Recursively convert almost any Python object to a JSON-serializable structure.
Installation
pip install jsonify-objects
Usage
dumps
Drop-in wrapper around json.dumps that handles non-serializable types.
from jsonify_objects import dumps
dumps({"a": 1, "b": True})
# '{\n "a": "1",\n "b": "true"\n}'
jsonify_objects
Returns the converted structure without serializing to a string.
from jsonify_objects import jsonify_objects
jsonify_objects({"a": 1, "b": True})
# {"a": "1", "b": "true"}
Behavior
Primitives
Primitive values inside plain dicts and lists are converted to strings.
| Type | Output |
|---|---|
int, float |
str(value) |
bool |
"true" / "false" |
str |
unchanged |
None |
null |
Enum |
str(value.value) |
dumps({"x": 42, "flag": True, "color": Color.RED})
# {"x": "42", "flag": "true", "color": "red"}
Dataclasses and objects
By default, non-serializable objects fall back to repr.
dumps({"user": UserDataclass("Alice", 30)})
# {"user": "UserDataclass(name='Alice', age=30)"}
Pass serialize_objects=True to expand objects and dataclasses into dicts.
Numeric fields on expanded objects preserve their native JSON types.
dumps({"user": UserDataclass("Alice", 30)}, serialize_objects=True)
# {"user": {"name": "Alice", "age": 30}}
Nested objects are expanded recursively.
dumps({"person": Person("Bob", Address("NYC"))}, serialize_objects=True)
# {"person": {"name": "Bob", "address": {"city": "NYC"}}}
Objects without a __dict__ (e.g. slots-only classes) fall back to repr.
indent
dumps accepts an indent parameter (default 2) passed through to json.dumps.
dumps({"a": 1}, indent=4)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jsonify_objects-1.0.0.tar.gz.
File metadata
- Download URL: jsonify_objects-1.0.0.tar.gz
- Upload date:
- Size: 15.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9321a630e95e77bbb5df9a523879c0349991f1ee2e3f5a6f3292e6085a95d424
|
|
| MD5 |
8a52f3831816c1b2e7ac24194a1b95dd
|
|
| BLAKE2b-256 |
03f673ae7fbf7fec71aec8e8b2982bd51f77cd988092f20caef3b533ffa04dbe
|
Provenance
The following attestation bundles were made for jsonify_objects-1.0.0.tar.gz:
Publisher:
publish.yml on BlakeJC94/jsonify-objects
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
jsonify_objects-1.0.0.tar.gz -
Subject digest:
9321a630e95e77bbb5df9a523879c0349991f1ee2e3f5a6f3292e6085a95d424 - Sigstore transparency entry: 1348599944
- Sigstore integration time:
-
Permalink:
BlakeJC94/jsonify-objects@c2033ee6725f30372d455bf065ffe7b76f251ce2 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/BlakeJC94
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c2033ee6725f30372d455bf065ffe7b76f251ce2 -
Trigger Event:
release
-
Statement type:
File details
Details for the file jsonify_objects-1.0.0-py3-none-any.whl.
File metadata
- Download URL: jsonify_objects-1.0.0-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b3fcf84e7701db0a32f2f1f2d1ba49e839b651b51ee0b1dedadc2a4efaa294ba
|
|
| MD5 |
eb42c3c632123cdf4af7751544b490dc
|
|
| BLAKE2b-256 |
08a111ecb0118178606980dba8d32a772e3ea31f243221bd3074f1bdb5c10877
|
Provenance
The following attestation bundles were made for jsonify_objects-1.0.0-py3-none-any.whl:
Publisher:
publish.yml on BlakeJC94/jsonify-objects
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
jsonify_objects-1.0.0-py3-none-any.whl -
Subject digest:
b3fcf84e7701db0a32f2f1f2d1ba49e839b651b51ee0b1dedadc2a4efaa294ba - Sigstore transparency entry: 1348600156
- Sigstore integration time:
-
Permalink:
BlakeJC94/jsonify-objects@c2033ee6725f30372d455bf065ffe7b76f251ce2 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/BlakeJC94
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c2033ee6725f30372d455bf065ffe7b76f251ce2 -
Trigger Event:
release
-
Statement type: