gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 19:30:01 26 4
gpt4 key购买 nike

我正在寻找一个 python 库,我可以在其中输入我的 JSON 模式并生成虚拟数据。我在 javascript dummy-json 中使用过类似的库。有没有人知道可以在 python 中执行相同操作的库。

最佳答案

做这件事的库是 hypothesis-jsonschema

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

hypothesis-jsonschema使得将 JSON Schema 转换为可供 Hypothesis 使用的规范成为可能。

下面是一个使用 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

关于从 JSON 模式生成 Python JSON 虚拟数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35231234/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com