Package: ujson
UltraJSONUltraJSON is an ultra fast JSON encoder and decoder written in pure C with bindings for
Python 3.8+.Install with pip:python-mpipinstallujsonUsageMay be used as a drop in replacement for most other JSON parsers for Python:>>>importujson>>>ujson.dumps([{"key":"value"},81,True])'[{"key":"value"},81,true]'>>>ujson.loads("""[{"key": "value"}, 81, true]""")[{'key': 'value'}, 81, True]Encoder optionsencode_html_charsUsed to enable special encoding of "unsafe" HTML characters into safer Unicode
sequences. Default isFalse:>>>ujson.dumps("<script>John&Doe",encode_html_chars=True)'"\\u003cscript\\u003eJohn\\u0026Doe"'ensure_asciiLimits output to ASCII and escapes all extended characters above 127. Default isTrue.
If your end format supports UTF-8, setting this option to false is highly recommended to
save space:>>>ujson.dumps("åäö")'"\\u00e5\\u00e4\\u00f6"'>>>ujson.dumps("åäö",ensure_ascii=False)'"åäö"'escape_forward_slashesControls whether forward slashes (/) are escaped. Default isTrue:>>>ujson.dumps("https://example.com")'"https:\\/\\/example.com"'>>>ujson.dumps("https://example.com",escape_forward_slashes=False)'"https://example.com"'indentControls whether indentation ("pretty output") is enabled. Default is0(disabled):>>>ujson.dumps({"foo":"bar"})'{"foo":"bar"}'>>>print(ujson.dumps({"foo":"bar"},indent=4)){"foo":"bar"}BenchmarksUltraJSONcalls/sec compared to other popular JSON parsers with performance gain
specified below each.Test machineLinux 5.15.0-1037-azure x86_64 #44-Ubuntu SMP Thu Apr 20 13:19:31 UTC 2023VersionsCPython 3.11.3 (main, Apr  6 2023, 07:55:46) [GCC 11.3.0]ujson        : 5.7.1.dev26orjson       : 3.9.0simplejson   : 3.19.1json         : 2.0.9ujsonorjsonsimplejsonjsonArray with 256 doublesencode18,28279,5695,6815,935decode28,76593,28313,84413,367Array with 256 UTF-8 stringsencode3,45726,4373,6303,653decode3,5764,2365221,978Array with 256 stringsencode44,769125,92021,40123,565decode28,51875,04341,49642,221Medium complex objectencode11,67247,6593,9135,729decode12,52223,5998,0079,720Array with 256 True valuesencode110,444425,91981,42884,347decode203,430318,193146,867156,249Array with 256 dict{string, int} pairsencode14,17072,5143,0507,079decode19,11627,5429,37413,713Dict with 256 arrays with 256 dict{string, int} pairsencode552821126decode48532734Dict with 256 arrays with 256 dict{string, int} pairs, outputting sorted keysencode42827Complex objectencode462397444decode480618177310Above metrics are in call/sec, larger is better.Build optionsFor those with particular needs, such as Linux distribution packagers, several
build options are provided in the form of environment variables.Debugging symbolsUJSON_BUILD_NO_STRIPBy default, debugging symbols are stripped on Linux platforms. Setting this
environment variable with a value of1orTruedisables this behavior.Using an external or system copy of the double-conversion libraryThese two environment variables are typically used together, something like:exportUJSON_BUILD_DC_INCLUDES='/usr/include/double-conversion'exportUJSON_BUILD_DC_LIBS='-ldouble-conversion'Users planning to link against an external shared library should be aware of
the ABI-compatibility requirements this introduces when upgrading system
libraries or copying compiled wheels to other machines.UJSON_BUILD_DC_INCLUDESOne or more directories, delimited byos.pathsep(same as thePATHenvironment variable), in which to look fordouble-conversionheader files;
the default is to use the bundled copy.UJSON_BUILD_DC_LIBSCompiler flags needed to link thedouble-conversionlibrary; the default
is to use the bundled copy.