从JSON模式生成Python JSON虚拟数据

use*_*735 11 python json dummy-data

我正在寻找一个python库,我可以在其中提供我的JSON模式,并生成虚拟数据.我在javascript dummy-json中使用过类似的库.有没有人关于一个库可以在python中做同样的事情.

Ali*_*ton 5

一个完全可以做到这一点的库是假设-jsonschema

假设是一个可以生成符合给定规范的任意数据的库。

Hypothesis-jsonschema可以将 JSON Schema 转换为 Hypothesis 可以使用的规范。

下面是一个示例,显示使用 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
Run Code Online (Sandbox Code Playgroud)


Döm*_*öme -2

以下是迄今为止提出的 JSON 模式生成器:

奖金:

  • 我不想生成架构。我有一个模式或者一个示例 JSON。我想从中生成随机数据。每次都应该是随机的 (3认同)