用于Python的超高速JSON编码器和解码器

ujson1的Python项目详细描述


这是ultrajson 1.35的兼容性分支,旨在与 通过将c扩展名重命名为“ujson1”来更新版本。在

主线ultrajson 3.x的开发重新开始 https://github.com/ultrajson/ultrajson请在那里发送请求 除非他们绝对有必要让你脱离1.x

https://travis-ci.org/esnme/ultrajson.svg?branch=master

UltraJSON是一个用纯C编写的超高速JSON编码器和解码器,绑定了Python2.5+和3。在

对于一个更加无痛的日常C/C++ JSON解码器经验,请基于UpjJSON检查{A3}。在

要安装它,只需像往常一样运行Pip:

$ pip install ujson

使用

可以作为Python的大多数其他JSON解析器的替换:

^{pr2}$

编码器选项

编码html字符

用于将“不安全”HTML字符特殊编码为更安全的Unicode序列。默认值为false:

>>> ujson.dumps("<script>John&Doe", encode_html_chars=True)
'"\\u003cscript\\u003eJohn\\u0026Doe"'

确保使用ascii

将输出限制为ASCII并转义127以上的所有扩展字符。默认值为true。如果end格式支持UTF-8,强烈建议将此选项设置为false以节省空间:

>>> ujson.dumps(u"\xe5\xe4\xf6")
'"\\u00e5\\u00e4\\u00f6"'
>>> ujson.dumps(u"\xe5\xe4\xf6", ensure_ascii=False)
'"\xc3\xa5\xc3\xa4\xc3\xb6"'

双精度

控制要为双精度值或十进制值编码的小数位数。默认值为9:

>>> ujson.dumps(math.pi)
'3.1415926536'
>>> ujson.dumps(math.pi, double_precision=1)
'3.1'
>>> ujson.dumps(math.pi, double_precision=0)
'3'
>>> ujson.dumps(math.pi, double_precision=4)
'3.1416'

转义正斜杠

控制是否转义正斜杠(/)。默认为真:

>>> ujson.dumps("http://esn.me")
'"http:\/\/esn.me"'
>>> ujson.dumps("http://esn.me", escape_forward_slashes=False)
'"http://esn.me"'

缩进

控制是否启用缩进(“精确输出”)。默认值为0(禁用):

>>> ujson.dumps({"foo": "bar"})
'{"foo":"bar"}'
>>> ujson.dumps({"foo": "bar"}, indent=4)
{
    "foo":"bar"
}

解码器选项

设置为在将字符串解码为双精度值时启用更高精度(strtod)函数。默认情况下,使用快速但不太精确的内置功能:

>>> ujson.loads("4.56")
4.5600000000000005
>>> ujson.loads("4.56", precise_float=True)
4.5599999999999996

试验机:

Linux 3.13.0-66-通用x86Ť108 Ubuntu SMP 2015年10月7日星期三15:20:27 UTC

版本:

  • CPython 2.7.6(违约,2015年6月22日,17:58:13)[GCC 4.8.2]
  • B列表:1.3.6
  • simplejson:3.8.1
  • ujson:1.34(0c52200eb4e2d97e548a765d5f089858c41967b0)
  • 雅居乐:0.3.5
ujsonyajlsimplejsonjson
Array with 256 doubles
encode3508.195742.003232.383309.09
decode25103.3711257.8311696.2611871.04
Array with 256 UTF-8 strings
encode3189.712717.142006.382961.72
decode1354.94630.54356.35344.05
Array with 256 strings
encode18127.4712537.3912541.2320001.00
decode23264.7012788.8525427.889352.36
Medium complex object
encode10519.385021.293686.864643.47
decode9676.535326.798515.773017.30
Array with 256 True values
encode105998.03102067.2844758.5160424.80
decode163869.9678341.57110859.36115013.90
Array with 256 dict{string, int} pairs
encode13471.3212109.093876.408833.92
decode16890.638946.0712218.553350.72
Dict with 256 arrays with 256 dict{string, int} pairs
encode50.2546.4513.8229.28
decode33.2722.1027.9110.43
Dict with 256 arrays with 256 dict{string, int} pairs, outputting sorted keys
encode27.197.752.39
Complex object
encode577.98387.81470.02
decode496.73234.44151.00145.16

版本:

  • CPython 3.4.3(违约,2015年10月14日,20:28:29)[GCC 4.8.4]
  • B列表:1.3.6
  • simplejson:3.8.1
  • ujson:1.34(0c52200eb4e2d97e548a765d5f089858c41967b0)
  • 雅居乐3.0
^{tb2}$

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
JavaSpringMVC控制器测试打印结果JSON字符串   若catch语句返回,那个么为什么它最终会阻塞呢?   java Grails中servletContext在哪里可用?   java Jhipster:如何为现有项目启用多种语言   java异常评估SpringEL表达式:“#fields.hasErrors('something')”   java如何验证SeleniumWebDriver中的文本颜色?   java在绘图时使用JPanel坐标   java如何初始化spring启动到project?   java如何通过JDBC的PreparedStatement将UUID数组插入HyperSQL数据库   java修改JVM以跨线程序列化文件访问   Javascript到Java正则表达式   使用Java运行时调用aspell程序时出现字符集问题。getRuntime()。执行官   执行RDP时的java Sukuli按钮识别   java如何使用okhttp更改connect请求的标头   java无法创建Maven Eclipse项目