Skip to content

About

C accelerated JSON serialisation for Python

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

14 Commits

Folders and files

Repository files navigation

Specific-json

A python JSON serialisation library implemented as a C extension.

  • Speed: Initial benchmarks show non-float/exponential json data to be on par with orjson and msgspec.
  • Memory: Initial benchmarks show memory usage close or sometimes less than msgspec.

See more at Benchmarks.

Checked/Tested against the JSONTestSuite!

Important

This project is under development and not meant to be used in prod. (if ever haha)

Features

  • Extremely fast implementations
  • Very low memory usage
  • Allows for python like indexing, hence avoiding creation of intermediate/unused python objects.

Benchmarks

Decoder decode (μs) vs.
msgspec structs 328.80 1.00x
msgspec 436.37 1.33x
specific-json 493.34 1.50x
orjson 520.14 1.58x
json 795.31 2.42x

Orjson Benchmarks

canada.json Fixture (Float Heavy)

Decoder decode (ms) vs.
orjson 5.808 1.00x
msgspec 6.418 1.10x
specific-json 21.312 3.67x
json 30.811 5.30x

citm_catalog.json Fixture (Object, Nested Structures, key & integer parsing)

Decoder decode (ms) vs.
orjson 2.393 1.00x
specific-json 2.641 1.10x
msgspec 2.735 1.14x
json 6.843 2.86x

github.json Fixture (General API response)

Decoder decode (ms) vs.
msgspec 0.089 1.00x
orjson 0.111 1.25x
specific-json 0.120 1.35x
json 0.164 1.84x

twitter.json Fixture (String & Unicode heavy)

Decoder decode (ms) vs.
orjson 1.017 1.00x
msgspec 1.296 1.27x
specific-json 1.680 1.65x
json 3.535 3.48x

Do take these benchmarks with a pinch of salt, these are results on my machine (Windows) and they have been modified to fit in one file for convenience. A more reliable benchmark will be used and uploaded in the future hopefully.

Installing

All major platforms are supported on Pypi!

Note

Python 3.12+ is required!

#windows
py -m pip install -U specific-json

#linux/macos
python3 -m pip install -U specific-json

Compiling

If you want to build this yourself, run this command to compile the extension in the root directory.

py setup.py build_ext --inplace

Example

from specific_json import json_decode

json_str = \
"""
{
  "name": "Sacul",
  "active": true,
  "tags": ["python", "c", "json"]
}
"""

def main():
    whole_obj = json_decode(json_str)

    is_active = json_decode(json_str, "active")
    first_tag = json_decode(json_str, "tags", 0)

    print(whole_obj)
    print(is_active)
    print(first_tag)

if __name__ == "__main__":
    main()

Development

The project is currently incomplete, see the TODO.

About

C accelerated JSON serialisation for Python

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages