问题标签 [python-jsonschema]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
0 回答
103 浏览

python - jsonschema - python - 如何验证包含 ref 的模式

我一直在努力弄清楚如何获得一个嵌套在定义中的模式$ref。如果我对 jsonschema 对象进行硬编码,我没有任何问题,但是我需要使用嵌套模式并且我不知道里面有schema=什么validate(json{"name": "lucky","uid": -1, schema='what do I put here to reference the ref schema?')

这是我用来隔离和测试功能的代码。

我已经尝试过 schemas['definitions']['user_record_with_ref'] 但这根本不起作用。也许这需要一个 ref 解析器?我认为它不会,因为子模式位于单个模式块内。任何帮助将不胜感激。

0 投票
0 回答
80 浏览

json - 如何在 linux cli 中针对 metaschema 验证 json 模式

我正在尝试验证我的复杂json 架构定义文件,以确保架构中没有错字。我使用python jsonschema libraryjsonschema提供的脚本。

我使用从json schema specification page下载的元模式文件。

我下载了“核心/验证方言元模式”文件和所有“单词汇元模式”,添加了“json”扩展并将这些文件存储在这个结构中:

如果我创建这个test01.json文件(注意第 5 行的“objectx”错字):

然后验证失败(如预期):

但是当我在嵌入对象(见第 8 行)中做出类似的错字时test02.json

然后验证通过(不打印输出):

如何从 linux 中的 CLI 验证复杂的 json 模式文档(不仅是顶级对象)?

0 投票
0 回答
38 浏览

python - 我想从 Selenium Scrape 数据中将地图保存在 JSON 文件中

我抓取了一个网站,从中获取了所有数据,我想将它存储在 json 文件中,以便我可以将它用作 API在 for 循环中,这是我尝试做的

我怎样才能附加到章节列表并保持标题不变我有更多的书也将是一个列表

这就是我得到的:

0 投票
1 回答
99 浏览

jsonschema - JSON Schema 相对引用解析

我正在尝试定义一个有效的 JSON 模式,但当被引用的组件位于子目录中时,我不确定如何构造引用 ("$ref") 值。我已经(详细地)阅读了官方 JSON Schema 站点上的信息,并检查了来自各种 JSON Schema 解析器的测试数据,但是可用的信息要么不清楚要么不可用(或者,当然,我找不到它尽管搜索了几个小时)...

我需要的具体帮助是确认组件目录中文件的引用(引用组件目录中的文件)是否应该在引用中用“组件”定义。(请注意,$id 不可用于提供基本 URI)。

换句话说,“message.schema.json”中的引用应该是:

  • 选项 1:“components/key.schema.json”和“components/data.schema.json”,或者,
  • 选项2:“key.schema.json”和“data.schema.json”(如下图)

在选项 1 中,“$ref”相对于父路径(“main.schema.json”),在选项 2 中,它相对于当前路径(“message.schema.json”)。

以下是提供进一步背景的信息。

文件结构比较简单,如下图所示:

文件内容如下所示...

main.schema.json:

上面的 JSON Schema 引用了“components”目录(main.schema.json 文件下的一个目录)中的文件。

message.schema.json:

并且上面的 message.schema.json 引用了与 message.schema.json 文件位于同一目录中的以下组件:

key.schema.json:

数据.schema.json:

0 投票
1 回答
54 浏览

jsonschema - jsonschemadependentSchema 未验证

我正在尝试学习 json 架构,但有些东西对我不起作用。我正在尝试从http://json-schema.org/understanding-json-schema/reference/conditionals.html#id4dependentSchemas运行示例,但它只是没有验证。

我正在使用这个架构:

而这个json,应该会引发一个错误,因为它缺少密钥billing_address

但是当我使用jsonschema.validate(dic_check, schema_check)(使用 python,jsonschema 包版本 4.2.1)时,验证通过没有问题。

我在这里做错了什么?

0 投票
1 回答
42 浏览

json - 我可以在 JSON Schema 验证中导入表吗?

我正在编写 JSON 模式验证。我有一个 ID 字段,其值是从 SQL Server 中的表导入的。这些值很大并且经常更新,那么有没有办法在服务器中动态连接到这个表并验证 JSON?下面是我的架构的示例代码:

代替“枚举”,我想连接到一个表,以便在更新表时更新 ID 值。

0 投票
1 回答
87 浏览

python - Python tools/libraries to validate a JSON schema

Are there any python libraries or tools that check if a JSON schema is valid?

I do not want to validate an instance against a JSON schema, but I would like to check if the JSON schema itself is valid or not. For example, if all the required fields are specified or not, or whether the data types are valid types or not.

I already had a look at check_schema() from jsonschema library, but this library does not check the aspects that I have mentioned above.

0 投票
0 回答
105 浏览

python - 从 JSON 模式生成 Python 类

我正在尝试从先前定义和创建的 JSON 模式开始在 Python 中生成一个新类。然后我想使用自动生成的类来读取 JSON 文件。我的问题是我设法使用“python_jsonschema_objects”或“marshmallow_jsonschema”从模式创建类,但是当我创建属于该类的对象时,python 不建议该类中的元素。(我想输入object.name,并且我希望python建议“名称”,因为它知道名称是对象的属性)。此外,这些工具创建的类在第一种情况下是“abc.class”,在第二种情况下是“类'marshmallow.schema.GeneratedSchema'”。我在这里留下一个代码示例:

我希望我已经足够清楚了。

0 投票
1 回答
50 浏览

python - 如何使用 jsonschema 和 Python 验证字典列表

我有一个这样的字典列表:

我想使用 jsonschema 包来验证它。

我创建了这样的架构:

但这对我的列表是不正确的,因为要使其正常工作,我的列表应该是这样的:

如何创建正确的架构来验证我的列表?先感谢您。

0 投票
1 回答
25 浏览

python - json-schema 的错误处理在 python 中重新定义了 type_checker

我正在使用json-schema来验证模式。我想自定义日期时间类型。因此,相应地重新定义了类型并扩展了验证器。但是,它并没有以我正在寻找的方式返回错误。我的代码:

errors 变量当前包含 schema 验证期间的所有错误,例如 id、age 等,但不包含 datetime 发生的错误。我正在从验证函数返回错误列表。没有错误时返回 True,否则返回错误列表。当我从邮递员发布错误的日期时间输入时,它返回 500 Internal Server Error,并且 vscode 在终端中显示此错误消息:

strptime raise ValueError("time data %r does not match format %r", %ValueError: time data '2015-01-35T05:05:05' does not match format '%Y-%m-%dT%H:%多发性硬化症'

如何让 json-schema 捕获它,以便我可以从错误中使用它?或任何其他能达到我想要得到的相同效果的解决方法。谢谢。