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 most prominent 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 more time-consuming and the last validictory is fast, but does not follow the standards.

So I created a library that is still in pure Python, but very fast. It works by producing a straightforward 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 essential 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.


1 response

Awesome work. Thanks!

You may also like

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

More posts from category code.
Do not miss new posts thanks to Atom/RSS feed.

Recent posts

cs Děkujeme za návštěvu, May 21, 2023 in family
cs Jak zadělat díru, April 25, 2023 in family
cs Od žárovky k rekonstrukci, April 14, 2023 in family
cs Ušák, March 12, 2023 in family
en Scrum vs Kanban → Scrum + Kanban, February 25, 2023 in code