问题标签 [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 投票
1 回答
1900 浏览

json - JSON 模式的自定义格式

我正在编写一个模式来存储在线课程数据,并希望指定必须使用以下格式输入课程长度:

例如:8 周、10 周、1 周……(我知道 1 周是个问题,但此时有问题)。

我如何要求以这种格式输入数据?

同样,如果我想指定必须输入开始日期,例如 2013 年 7 月 1 日,我该怎么做?

另外,我知道 JSON 模式中有日期格式。1问题是这种格式与上面指定的格式不匹配。

0 投票
2 回答
3801 浏览

python - 报告所有验证错误而不是第一次失败的简单 python 验证库?

我试过 voluptuousand schema,这两种方法都很简单而且验证效果很好,但是它们都做基于异常的错误报告,即它们在第一个错误时失败。有没有办法可以获取 Voluptuous 或 Schema 中数据的所有验证错误?

我发现jsonschema这似乎符合某些要求,但没有对对象键的验证和基于自定义函数的验证(例如 lambdas)。

要求:

0 投票
1 回答
470 浏览

json - json模式如何验证混合属性?

如果我有一个像上面这样的 json 数据,并且属性“a”和“b”实际上是用户给出的名称,那么它可以是任何字符串。如何创建一个 json 模式来验证这一点?

0 投票
3 回答
28490 浏览

json - Only allow properties that are declared in JSON schema

I am using json-schema and wanting to only allow properties that are declared in this file to pass validation. For instance if a user passes a "name" property in their json object it will fail this schema because "name" is not listed here as a property.

Is there some function similar to "required" that will only allow the listed properties to pass?

0 投票
1 回答
130 浏览

arrays - jsonschema: Verifying that an array contains an element, without erroring on other elements

I recently found jsonschema and I've been loving using it, however recently I've come across something that I want to do that I just haven't been able to figure out.

What I want to do is to validate that an array must contain an element that matches a schema, but I don't want to have validation fail on other elements that would be in the list.

Say that I have an array like the following:

I want to be able to do something like "validate that arr contains an object that has a property 'some object' that is a boolean, and error if it doesn't, but don't care about other elements."

I don't want it to validate the other items in the list. I just want to make sure that the list contains an element that matches the schema at least once. I also do not know the order which the elements will arrive in the array.

I've tried this already with a schema like:

The problem is that it requires every item in the array to have the property "tool", and not what I actually want.

Any help anyone can give me with this would be much appreciated! I've been stumped on this for a really long time with no forward progress.

Thanks!

0 投票
1 回答
718 浏览

json - 如何让 JSON Schema 识别对象的层次结构?

我正在为 JSON 编写模式。假设我有一个名为“功能”的对象。在这个对象内部定义了各种属性,其中一个是“特征”,它是一个包含另一组“特征”的数组。所以层次实际上是无限的。

“特征”数组可以包含更多的“特征”对象,每个对象也可能有更多的“特征”。我可以在 JSON 模式中适应这个吗?

0 投票
1 回答
29916 浏览

json - 关于使用 $ref 的 JSON 模式

我知道 $ref 需要一个 URI 来使用 json 模式,但是 $ref : "#" 指向哪里?这是否只是意味着在这个块级别使用当前模式?或者这是否意味着使用根级别 id 中定义的根级别架构?谢谢

编辑:所以如果我有:

因为它缺少一个 id 字段,它会首先尝试使用根模式验证实例项,然后如果失败,则尝试使用定义模式中定义的 schemaArray 模式验证它,对吧?

因此,如果我将其更改为:

那么 anyOf 数组中的第一个子模式将指向项目模式本身吗?

编辑#2:好的,如果我有:

“stringArray”的“items”字段将根据上述“itemsSchema”进行验证?

'anyOf' 中的第二个 $ref 是否通过转到根目录然后遍历路径直到它到达该模式来工作?谢谢!

0 投票
1 回答
253 浏览

json - 什么 JSON 对关键字“anyOf”有效

我想知道是否有人可以给出一个对使用“anyOf”关键字的模式有效的 JSON 示例?我正在尝试编写一些将在 python 中输出有效 JSON 的代码。

例如,如果您有一个如下所示的架构:

什么 JSON 是有效的?

我用来在 python 中输出 JSON 的代码是这样的:

0 投票
1 回答
690 浏览

json - JSON .Net 错误地生成模式(类型为数组)

当使用 JSON.Net JsonSchemaGenerator 为我的对象生成 JSON Schema 时:

它将 type 属性生成为字符串数组:

正确的 JSON Schema 应该是:

有没有人见过这个?

0 投票
2 回答
2307 浏览

python - 架构未验证

我正在使用 JSON 模式,并且正在尝试使用 python JSON 模块来验证我针对该模式输出的一些 JSON。

我收到以下错误,表明 Schema 本身没有验证:

我认为,validationError 消息表明冒号后面的内容不是有效的 JSON 对象,但我不知道为什么它不是。

如果您将单引号替换为双引号并从任一侧删除基本括号,则此 JSON 将使用 JSON Lint 之类的验证器进行验证。


名称前的“u”已被标记为可能的错误。

这是输出名称的代码:

使用以下命令将名称插入 JSON: