New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mrjson

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mrjson

JSON encoder and decoder for Python

  • 1.4
  • PyPI
  • Socket score

Maintainers
1

MrJSON

MrJSON is a JSON encoder and decoder written in C/C++ with bindings for Python 2.5+ and 3. I needed faster performance for long strings and floats and MrJSON benchmarks at 2-3 times faster than the fastest python parsers for my use cases.

To install it just run Pip as usual:

    $ pip install mrjson

Usage

May be used as a replacement for json

    >>> import mrjson as json
    >>> json.dumps([{"key": "value"}, 81, True])
    '[{"key":"value"},81,true]'
    >>> json.loads("""[{"key": "value"}, 81, true]""")
    [{'key': 'value'}, 81, True]

Encoder differences

ensure_ascii defaults to true in the base json module, but defaults to false here for space and performance reasons.

indent, separators, and sortKeys are not supported as pretty printing doesn't need the performance. Write an issue if you have a use case.

allow_nan is unsupported as NaN and infinity are supported by default.

Custom objects are supported if they implement an json() method returning a valid json string.

Benchmarks

Benchmark your own files as results can vary significantly:

$ python -m timeit -s "import mrjson as json;st = open('canada.json').read();" "json.loads(st)"
100 loops, best of 3: 8.05 msec per loop

$ python -m timeit -s "import json;st = open('canada.json').read();" "json.loads(st)"
10 loops, best of 3: 32.7 msec per loop

Or run bench.py to test MrJSON against some other modules. MrJSON does particularly well decoding long strings and floating point numbers thanks to intel's AVX2 instructions and Milo Yip at Tencent for publishing C++ code implementing Florian Loitsch's float to string algorithms.

Loads

Only 128 byte long strings.

Mostly floating point numbers - canada.json from The Native JSON Benchmark, the fastest C++ JSON parser comes in at 7.9 milliseconds on this machine for comparison

A single tweet from twitter - twit.json

citm_catalog.json from The Native JSON Benchmark

Dumps

Only 128 byte long strings.

Mostly floating point numbers - canada.json from The Native JSON Benchmark

A single tweet from twitter - twit.json

citm_catalog.json from The Native JSON Benchmark

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc