【问题标题】:Python JSON dummy data generation from JSON schema从 JSON 模式生成 Python JSON 虚拟数据
【发布时间】:2016-05-15 20:21:41
【问题描述】:

我正在寻找一个 python 库,我可以在其中输入我的 JSON 模式并生成虚拟数据。我在 javascript dummy-json 中使用过类似的库。有谁知道可以在 python 中做同样事情的库。

【问题讨论】:

标签: python json dummy-data


【解决方案1】:

一个完全做到这一点的库是hypothesis-jsonschema

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

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

这是一个显示使用 Hypothesis 和 hypotheses-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

【讨论】:

    【解决方案2】:

    我在 python 中找到的最接近的是https://github.com/ueg1990/faker-schema,但它不是 JSON-SCHEMA,也有 nodejs 实现,它直接是您正在搜索的https://github.com/json-schema-faker/json-schema-faker

    【讨论】:

      【解决方案3】:

      这里是目前提出的 JSON 模式生成器:

      奖金:

      【讨论】:

      猜你喜欢
      • 2015-07-29
      • 2017-02-22
      • 2016-05-17
      • 2011-11-12
      • 2021-12-05
      • 1970-01-01
      • 2019-06-23
      • 2017-05-24
      相关资源
      最近更新 更多