Fastest JSON encode / decode library.
Project description
yapic.json is an extreamly fast json encoder / decoder package for python. Encoding and decoding output fully compatible with python.json package.
Features
Extreamly fast (see benchmark results in ‘/benchmark’ directory)
Fully compatible output with Python json package
Builtin object serialization method __json__ (see below)
Strict JSON (RFC 4627) expected: Infinity, NaN (JavaScript compatible infinity and not a number symbols)
UTF-8 encoding & decoding support
Accurate float encoding & decoding
date / datetime / time encondig & decoding support (can encode subclasses)
uuid.UUID encoding support
ItemsView encoding support
from collections.abc import ItemsView class MyDictGenerator(ItemsView): def __iter__(self): yield ("some_key", "some_value") yield ("meaning_of_life", 42) json.dumps(MyDictGenerator()) == '{"some_key":"some_value","meaning_of_life":42}'
Requirements
Only works with Python 3.5 or greater
c++ 11 comaptible compiler. (only if u want to build from source)
Wheels provided for windows x86/x64 and linux x86/x64 and osx x64
Usage
Very similar that python.json, let’s see some example
Json data to python
from yapic import json
>>> json.loads('"Hello World"')
"Hello World"
Python object to json data
from yapic import json
>>> json.dumps("Hello World")
'"Hello World"'
class Point:
def __json__(self):
return {"x":1, "y":2}
>>> json.dumps(Point())
'{"x":1,"y":2}'
Functions
loads (s: bytes, str, *, object_hook: Callable[[dict], Any]]=None, parse_float: Callable[[str], Any]]=None, parse_date: bool=True)
object_hook example:
>>> from yapic import json >>> def hook(dict_): ... if "__complex__" in dict_: ... return complex(dict_["real"], dict_["imag"]) ... >>> json.loads('{"__complex__":true, "real":1, "imag":2}', >>> object_hook=hook) (1+2j)
parse_float example:
>>> from yapic import json >>> from decimal import Decimal >>> json.loads("1.2", parse_float=Decimal) Decimal('1.2')
dumps (obj: Any, *, default: Callable[[Any], JSONT]=None, tojson: str="__json__", ensure_ascii: bool=True, encode_datetime: bool=True) -> str
default example:
>>> from yapic import json >>> def default_func(o): ... if isinstance(o, complex): ... return {"__complex__": True, "real": 1, "imag": 2} ... >>> json.dumps(1 + 2j, default=default_func) '{"__complex__":true,"real":1,"imag":2}'
tojson example:
>>> from yapic import json >>> class Point(object): ... def __init__(self, x, y): ... self.x = x ... self.y = y ... def __json__(self): ... return {"x": self.x, "y": self.y} ... >>> json.dumps(Point(10, 20)) '{"x":10,"y":20}'
dumpb (obj: Any, *, default: Callable[[Any], JSONT]=None, tojson: str="__json__", ensure_ascii: bool=True, encode_datetime: bool=True) -> bytes
Same as dumps, but this function is return bytes insted of str
Exceptions
yapic.json.JsonError: base exception class
yapic.json.JsonEncodeError: exception class for encoding errors
yapic.json.JsonDecodeError: exception class for decoding errors
Json to Python translations
Json |
Python |
---|---|
“string” |
str |
42 |
int |
4.2, 4e2 |
float (unless you specify parse_float) |
Infinity |
float(“inf”) |
NaN |
float(“NaN”) |
true |
True |
false |
False |
null |
None |
2000-01-01 12:34:56 |
datetime without timezone |
2000-01-01 12:34:56Z |
datetime with utc timezone |
2000-01-01 12:34:56+0300 |
datetime with custom timezone |
2000-01-01 |
date |
10:12:34 |
time without timezone |
10:12:34+0300 |
time with custom timezone |
{…} |
dict (unless you specify object_hook) |
[…] |
list |
Python to Json translations
Python |
Json |
---|---|
str |
“…” |
int(42) |
42 |
float(4.2), Decimal(4.2) |
4.2 |
float(“inf”), Decimal(“inf”) |
Infinity |
float(“nan”), Decimal(“nan”) |
NaN |
True |
true |
False |
false |
None |
null |
datetime |
“2000-01-01 12:34:56”, “2000-01-01T12:34:56+0300” |
date |
“2000-01-01” |
time |
“12:34:56”, “12:34:56+0300” |
UUID |
“aba04c17-6ea3-48c1-8dcd-74f0a9b79bee” |
dict, ItemsView |
{…} |
list, tuple, set, iterable |
[…] |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for yapic.json-1.6.1-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5833a5dd818ef7b79a5d622c6272f47b903df47631d453fea33d280ce419c940 |
|
MD5 | 673f651abf7066f393d23d5646b97009 |
|
BLAKE2b-256 | 8ce7b41c99cc5c96163057099be395f25919e72dea059b7a0b2a59253443d318 |
Hashes for yapic.json-1.6.1-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6632efccb8e92c91eeb48d2efbd21a26904530525b650ed95aa9a9130b21b6b2 |
|
MD5 | e4ab83b7aef086c62570454885d9774e |
|
BLAKE2b-256 | 0435900f61d1495894f17dda29165ee25e33f003a6bee1d40c0dc8cefb218e44 |
Hashes for yapic.json-1.6.1-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b134ce64153358c88761a49d853a5692ab0841a990012ba022ff47862359b19c |
|
MD5 | 1c1364613cc4b4301717294466c9199e |
|
BLAKE2b-256 | dc39c0b163649bef70c3180422001eb82ce02bab4151f01bec28b75790efe750 |
Hashes for yapic.json-1.6.1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 444511a8134a1e2a6396cbc596d84c3d63b1affc86019e99fa83285cdd41a474 |
|
MD5 | 7cf217f1061004c3848d995db519beb1 |
|
BLAKE2b-256 | ed26b263fd31b2be585797e593adcfc41e39a3509d771b1b75b84346c61e1dc6 |
Hashes for yapic.json-1.6.1-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a51e579e43e81a47e8d41377bcecdd234c9905abe38f309494d9584e8f7f371c |
|
MD5 | ff6c81c305d6e0ec8e6dc23f26a651bb |
|
BLAKE2b-256 | 29869c3e77d684a831e4697dd5405c9e7846ee12e1f9dfcc91157026562b2f56 |
Hashes for yapic.json-1.6.1-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3571b67860402659a1c65190e7974298b72bce97572968160fea92d76c38e897 |
|
MD5 | 005526c33d5dbdf0d4e0fa3cd82c4f7f |
|
BLAKE2b-256 | 1a908b9b2f1df4ceb6d9a5c5e5fab91dc72e5471b7fe5fcb8c6664d10ae1514b |
Hashes for yapic.json-1.6.1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 991b0b7bb4e154a18794483f142f470bacc8bbe1e3a380924bbfbb7f87d390cd |
|
MD5 | 446408301302a323b23dd90895160496 |
|
BLAKE2b-256 | 342a9be4134886b0f239653134f5dc30a1308a77fb9df3f8d2440389a0a2aa38 |
Hashes for yapic.json-1.6.1-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | deaca63d063e36d60696f113353ec2becb83e2c3a8ea0f5be40d1f48475e65cb |
|
MD5 | b1b38ebd335d75982e34210a40797f56 |
|
BLAKE2b-256 | 9f7d966d044d90f596dbaf68ae0181abd3ac15f9a1fc1f4e0ed0f9795f2d1e50 |
Hashes for yapic.json-1.6.1-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f031bfcc5c26b1c1af10e5d6625052612fc8ac6bbe382dee9500e2fd935fd6c |
|
MD5 | 764c3fed531d26fd9ae3103d0771cc1f |
|
BLAKE2b-256 | ef21a1bf43fbf2c1a46b9f9641206733d3c73b4c74c439fa66a0f1a8297c4625 |
Hashes for yapic.json-1.6.1-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 855c85c9045b70d02bad5b0beb6eb1a5d7b87e0f533e852cf65f102c647c414f |
|
MD5 | cc409fdaca3fce452801fd6cdff5e6de |
|
BLAKE2b-256 | c8c9f009568e05d79e6c3ae02cb29ef3568690a36fae9459d473303ce414b984 |
Hashes for yapic.json-1.6.1-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 929369b72d24e038eb0bc77414d76ab39b041d933070cba252ce5b54353c7ba8 |
|
MD5 | 8c7cfe3846d4e6fcc4f40c330c82f8d3 |
|
BLAKE2b-256 | bab7d2f0b24bfc278d6d808a63f848f74ce45ed85255794e3a724ce0d6a535a7 |
Hashes for yapic.json-1.6.1-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c1e9503f0d8506fc68db9103adec25060722ca2703c408a3f0047339172154e |
|
MD5 | bd3dcbb8e9c64f1d38fa7e5a3f53c5de |
|
BLAKE2b-256 | 26c2eff13080a950d0cc471345a54797079721f03ce7a72c305f19b1c47c8466 |
Hashes for yapic.json-1.6.1-cp35-cp35m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 980d122a8f8c8bbc6013fb67148452b53b492222c5e3b4f07be5e42a86af2441 |
|
MD5 | 0dc116a8cee2cfb65717b377345cf791 |
|
BLAKE2b-256 | 2796ae18f6737c86519e860baecbe56ede3ebbcdf1db62320268f5dbda40127f |