Json library
Project description
JsonEx
W tej bibliotece poprawiono tworzenie jsona gdzie wcześniej zwracało błędy
Od teraz przy próbie zapisania do jsona list
, dicts
, set
oraz customowych objektów nie powinno sprawiać problemu,
dla objektów które nie mogą być sformatowane na json zostanie zwrócona wartość
f"[custom type: {type(value).__name__}]"
Przykłady
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 w JSON
True, # boolean true w JSON
False, # boolean false w JSON
123, # liczba całkowita (int)
45.67, # liczba zmiennoprzecinkowa (float)
"tekst", # ciąg znaków (str)
[1, 2, 3], # tablica (list)
{"klucz": "wartość"}, # obiekt (dict)
(4, 5, 6), # tuple
{7, 8, 9}, # set (zestaw)
# Dodatkowe przykłady dla pełności
456, # kolejny int
78.9, # kolejny float
"inny tekst", # kolejny str
[4, 5, 6], # kolejna list
{"inny_klucz": "inna_wartość", "klucz2": (1, 2, 3)}, # kolejny dict
(10, 11, 12), # kolejny tuple
{10, 11, 12}, # kolejny set
True, # kolejny bool
CustomObject(),
df,
{"a", "b", "c"}
]
print(JsonEx.dump(data))
Zwróci:
[null, true, false, 123, 45.67, "tekst", [1, 2, 3], {"klucz": "warto\u015b\u0107"}, [4, 5, 6], [8, 9, 7], 456, 78.9, "inny tekst", [4, 5, 6], {"inny_klucz": "inna_warto\u015b\u0107", "klucz2": [1, 2, 3]}, [10, 11, 12], [10, 11, 12], true, "[custom type: CustomObject]", "[custom type: DataSource]", ["c", "b", "a"]]
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.0.tar.gz
(3.1 kB
view details)
Built Distribution
jsonex-1.0-py3-none-any.whl
(3.3 kB
view details)
File details
Details for the file jsonex-1.0.tar.gz
.
File metadata
- Download URL: jsonex-1.0.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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8220f5a73ef15741e2d9f621850c58363af35f83208994cacc662be5754b361c |
|
MD5 | 6fc5fd2c1d8b00fcc8cbf6c6db21a473 |
|
BLAKE2b-256 | 5b0d599602e69495cb7feda36e5a14283fc2c0e9c0219d0b5f7b0f963531835a |
File details
Details for the file jsonex-1.0-py3-none-any.whl
.
File metadata
- Download URL: jsonex-1.0-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
Algorithm | Hash digest | |
---|---|---|
SHA256 | caf27cd8b4da690bc9f10a58153a13254c0540fd07743bd8f0c02190a3711c43 |
|
MD5 | df2f32b78b6b32eb1de15f2d3f7a9df0 |
|
BLAKE2b-256 | 12444359c36a722f3744587c71c6c551747b457dd7574302a2e08fdd7c61ad25 |