Fast JSON Schema for Python

en in code • 2 min read

JSON is used in many places. It’s easy to learn, read and use. JSON is also compact and won the battle with an XML to be a generic format to exchange data. But JSON has its problems as well. The biggest issue, I would say, is the same as the biggest feature—it’s very free.

We have to be able to validate data and for the JSON, there is JSON schema. “A vocabulary that allows you to annotate and validate JSON documents.”

Many languages implemented that in many libraries. Unfortunately, when you need to process a lot of data, but not A LOT to switch to a compiled language, it can be very slow.

For example, in Python, there are three main libraries. The most popular jsonschema is slow, the second most popular json-spec is even slower and the last validictory is fast, but does not follow the standards.

So I created a library which is still in pure Python, but very fast. It works by producing a very simple and stupid Python code. Not complicated objects or other constructs.

The result?

  • jsonschema takes 5 seconds
  • json-spec takes 7 seconds
  • validitory takes 380 miliseconds (but with bugs)
  • and mine fastjsonschema takes only 250 miliseconds

fastjsonschema has been here since 2016, but it supported only the most important features of JSON schema. Now, there is second version supporting all JSON features (including draft 06 and 07) and is still incredibly fast. :-)

I’m giving big thanks to all contributors who helped to implement missing features and find the bugs.

Enjoy!

https://github.com/horejsek/python-fastjsonschema





You may also like

en Open Source Responsibilities, September 6, 2018
en Deployment of Python Apps, August 15, 2018
en Nginx X-Accel Explained, July 31, 2018
en Cute Features, July 23, 2018
en Rewrite Stuff, July 13, 2018


Popular from code

en Makefile with Python, November 6, 2017
en Deployment of Python Apps, August 15, 2018
cs Jasně, umím Git…, August 6, 2014
cs Checklist na zabezpečení webových aplikací, March 1, 2016
cs Pokročilé regulární výrazy, August 17, 2014