Skip to main content

JsonEx

In this library, the creation of JSON has been improved where it previously returned errors.

From now on, attempting to save list, dicts, set, and custom objects to JSON should not cause any problems. For objects that cannot be formatted into JSON, the following value will be returned:

f"[custom type: {type(value).__name__}]"

Custom data auto convert:

pandas DataFrame => dict
numpy ndarray => list

Encode json

from jsonex import JsonEx

JsonEx.dump({})

Decode json

from jsonex import JsonEx

json = JsonEx.dump({})

JsonEx.load(json)

Example

from jsonex import JsonEx
import numpy as np


class CustomObject:
    a: int
    b: int

df = np.DataSource()


CustomObject.a = 42
CustomObject.b = 33

data = [
    None,  # null in JSON
    True,  # boolean true in JSON
    False,  # boolean false in JSON
    123,  # integer (int)
    45.67,  # floating-point number (float)
    "text",  # string (str)
    [1, 2, 3],  # array (list)
    {"key": "value"},  # object (dict)
    (4, 5, 6),  # tuple
    {7, 8, 9},  # set
    # Additional examples for completeness
    456,  # another int
    78.9,  # another float
    "another text",  # another str
    [4, 5, 6],  # another list
    {"another_key": "another_value", "key2": (1, 2, 3)},  # another dict
    (10, 11, 12),  # another tuple
    {10, 11, 12},  # another set
    True,  # another bool
    CustomObject(),
    df,
    {"a", "b", "c"}
]
print(JsonEx.dump(data))

Zwróci:

[null, true, false, 123, 45.67, "text", [1, 2, 3], {"key": "value"}, [4, 5, 6], [8, 9, 7], 456, 78.9, "another text", [4, 5, 6], {"another_key": "another_value", "key2": [1, 2, 3]}, [10, 11, 12], [10, 11, 12], true, "[custom type: CustomObject]", "[custom type: DataSource]", ["a", "b", "c"]]

Metadata

Release files for jsonex 1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jsonex 1.3
File Size Uploaded
jsonex-1.3.tar.gz 4.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jsonex 1.3
File Interpreter ABI Platform
jsonex-1.3-py3-none-any.whl Python 3 none any Details

Total release size: 9.3 kB

Release files / jsonex-1.3.tar.gz

Download URL jsonex-1.3.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
94fea6cc6603795f0497e3251b0277fd4b793f0bd976bbde67930f55b09a869a
BLAKE2b-256 checksum
How to use checksums
5a911f25abc1f9796122d4074d771243bee62caa0cca76a4536da346bc11a895
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.3

Release files / jsonex-1.3-py3-none-any.whl

Download URL jsonex-1.3-py3-none-any.whl
Size 5.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2c0f7304a575354098ab756e98c219166948903ba0ee97778889555c77e0fb53
BLAKE2b-256 checksum
How to use checksums
9566fe125e152edcbd530253d55241410c625bc44a3f2235cbd3cc68013e74a0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

1.3 This release

2 release files

1.2

2 release files

1.1

2 release files

1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page