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

Uploaded Source

Built Distribution

jsonex-1.2-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for jsonex-1.2.tar.gz
Algorithm Hash digest
SHA256 51940990e52348b47fddf5866b12c6960c1d77146a4a86430b10bd620913d86c
MD5 21f1ca075948277abe0b6f30c796abf1
BLAKE2b-256 a81412c4d531437a2468be4c49e2f11203e22ec505cd746e71c1d34070f52e44

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jsonex-1.2-py3-none-any.whl
  • Upload date:
  • Size: 4.6 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e4aeeb3e2c53948e6b77b18211179201118c682fa1095a7941dfe21194625f24
MD5 c994b6026b7610c90af5e22eed53404a
BLAKE2b-256 dafc70668f437cd7dd38f28067970de479af5c6c5bef60fc92449e19a9d83820

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