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

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.1.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

jsonex-1.1-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: jsonex-1.1.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for jsonex-1.1.tar.gz
Algorithm Hash digest
SHA256 a33ef359f5397f82c4303da06e26234a085f410e1898dedbb46158cc865b5cf6
MD5 858369f600e37a3d46f35bce810c9e7c
BLAKE2b-256 2f597f3c2b2f717346116194068b7a505f44d5552f6ad2f01e0af5e87ea7c3ff

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonex-1.1-py3-none-any.whl
  • Upload date:
  • Size: 3.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for jsonex-1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a9aa31df9e458deab40f11783aef1c9e780bc2dd9ffc36e1df8040754a543cff
MD5 b564f80b1afe5ced2abeb72fcb8e5644
BLAKE2b-256 b0edba7253184ccf1131e2792eb9787d75280a1f6a1a523f81e86db180ec5b4a

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