Python JSON dummy data generation from JSON schema

user1733735 picture user1733735 · Feb 5, 2016 · Viewed 9.4k times · Source

I am looking for a python library in which I can feed in my JSON schema and it generates dummy data. I have worked with a similar library in javascript dummy-json. Does anyone about a library which can do the same in python.

Answer

Alice Heaton picture Alice Heaton · Jun 7, 2021

A library that does exactly this is hypothesis-jsonschema

Hypothesis is a library that can generate arbitrary data that conforms to a given specification.

hypothesis-jsonschema makes it possible to convert JSON Schema into specifications that can be used by Hypothesis.

Here is an example showing a unit test written using Hypothesis and hypothesis-jsonschema:

from hypothesis import given

from hypothesis_jsonschema import from_schema


@given(from_schema({"type": "integer", "minimum": 1, "exclusiveMaximum": 10}))
def test_integers(value):
    assert isinstance(value, int)
    assert 1 <= value < 10