Skip to main content

Json library

Project description

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"]]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jsonex-1.3.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

jsonex-1.3-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file jsonex-1.3.tar.gz.

File metadata

  • Download URL: jsonex-1.3.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for jsonex-1.3.tar.gz
Algorithm Hash digest
SHA256 94fea6cc6603795f0497e3251b0277fd4b793f0bd976bbde67930f55b09a869a
MD5 a9d700fa5b505c1bc23ba873f823a968
BLAKE2b-256 5a911f25abc1f9796122d4074d771243bee62caa0cca76a4536da346bc11a895

See more details on using hashes here.

File details

Details for the file jsonex-1.3-py3-none-any.whl.

File metadata

  • Download URL: jsonex-1.3-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for jsonex-1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2c0f7304a575354098ab756e98c219166948903ba0ee97778889555c77e0fb53
MD5 14bcf668ed444c6b26b2c9a7c9f03df7
BLAKE2b-256 9566fe125e152edcbd530253d55241410c625bc44a3f2235cbd3cc68013e74a0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page