Package: yapic.json
yapic.jsonis an extreamly fast json encoder / decoder package for python.
Encoding and decoding output fully compatible withpython.jsonpackage.FeaturesExtreamly fast(see benchmark results in ‘/benchmark’ directory)Fully compatible output with Python json packageBuiltin object serialization method__json__(see below)StrictJSON (RFC 4627)expected:Infinity,NaN(JavaScriptcompatible infinity and not a number symbols)UTF-8 encoding & decoding supportAccurate float encoding & decodingdate/datetime/timeencondig & decoding support(can encode subclasses)uuid.UUIDencoding supportItemsViewencoding supportfromcollections.abcimportItemsViewclassMyDictGenerator(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}'RequirementsOnly works with Python 3.5 or greaterc++ 11 comaptible compiler.(only if u want to build from source)Wheels provided forwindows x86/x64andlinux x86/x64andosx x64On Windows you maybe need to installMicrosoft Visual C++ RedistributableWindowsUsageVery similar thatpython.json, let’s see some exampleJson data to pythonfromyapicimportjson>>>json.loads('"Hello World"')"Hello World"Python object to json datafromyapicimportjson>>>json.dumps("Hello World")'"Hello World"'classPoint:def__json__(self):return{"x":1,"y":2}>>>json.dumps(Point())'{"x":1,"y":2}'Functionsloads(s:bytes,str,*,object_hook:Callable[[dict],Any]]=None,parse_float:Callable[[str],Any]]=None,parse_date:bool=True)object_hook example:>>>fromyapicimportjson>>>defhook(dict_):...if"__complex__"indict_:...returncomplex(dict_["real"],dict_["imag"])...>>>json.loads('{"__complex__":true, "real":1, "imag":2}',>>>object_hook=hook)(1+2j)parse_float example:>>>fromyapicimportjson>>>fromdecimalimportDecimal>>>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) ->strdefault example:>>>fromyapicimportjson>>>defdefault_func(o):...ifisinstance(o,complex):...return{"__complex__":True,"real":1,"imag":2}...>>>json.dumps(1+2j,default=default_func)'{"__complex__":true,"real":1,"imag":2}'tojson example:>>>fromyapicimportjson>>>classPoint(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) ->bytesSame asdumps, but this function is returnbytesinsted ofstrExceptionsimportjsonaspy_jsonclassJsonError(ValueError):"""Base exception for all json errors"""classJsonEncodeError(JsonError):"""Exception for encoding errors"""classJsonDecodeError(JsonError,py_json.JSONDecodeError):"""Exception for decoding errors

   Can match python builtin ``json.JSONDecodeError``.
   """# alias for easier switch from std json libJSONDecodeError=JsonDecodeErrorJson to Python translationsJsonPython“string”str42int4.2, 4e2float (unless you specify parse_float)Infinityfloat(“inf”)NaNfloat(“NaN”)trueTruefalseFalsenullNone2000-01-01 12:34:56datetime without timezone2000-01-01 12:34:56Zdatetime with utc timezone2000-01-01 12:34:56+0300datetime with custom timezone2000-01-01date10:12:34time without timezone10:12:34+0300time with custom timezone{…}dict (unless you specify object_hook)[…]listPython to Json translationsPythonJsonstr“…”int(42)42float(4.2), Decimal(4.2)4.2float(“inf”), Decimal(“inf”)Infinityfloat(“nan”), Decimal(“nan”)NaNTruetrueFalsefalseNonenulldatetime“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”EnumencodingEnum.valueattributedict, ItemsView, dataclass{…}list, tuple, set, iterable[…]