使用条件语句的json模式定义

时间:2018-08-29 05:59:16

标签: json jsonschema json-schema-validator

我试图使用json模式条件语句(使用草案7)定义可选条件

我有一个这样的json响应。

crossing

在此响应中,如果tile对象包含键badData <- data.frame(start= c(296,330,350),end=c(310.01,335,565)) library(dplyr) library(tidyr) library(data.table) df %>% crossing(badData) %>% mutate(Flag=ifelse(data.table::between(wavelength,start,end),1,0)) %>% arrange(wavelength,desc(Flag)) %>% #Make sure 1 'if exist' at the 1st row for each wavelength before run distinct distinct(wavelength,.keep_all=T) %>% mutate(reflectance_upd=ifelse(Flag==1,NA,reflectance)) wavelength reflectance start end Flag reflectance_upd 1 300.0000 -1.000000 296 310.01 1 NA 2 305.0087 -6.008667 296 310.01 1 NA 3 310.0173 -11.017334 296 310.01 0 -11.01733 4 315.0260 -16.026001 296 310.01 0 -16.02600 5 320.0347 -21.034668 296 310.01 0 -21.03467 6 325.0433 -26.043335 296 310.01 0 -26.04333 7 330.0520 -31.052002 330 335.00 1 NA 8 335.0607 -36.060669 296 310.01 0 -36.06067 9 340.0693 -41.069336 296 310.01 0 -41.06934 10 345.0780 -46.078003 296 310.01 0 -46.07800 11 350.0867 -51.086670 350 565.00 1 NA 12 355.0953 -56.095337 350 565.00 1 NA ,则必填字段必须为[{ "views": [{ "name": "RSO Roster", "displayOrder": 5, "groups": [{ "type": "scrollable", "displayOrder": 1, "auditType": "player-pregame_roster", "tiles": [{ "context": "event", "dataStamp": 1535184247, "tile_type": "person" }, { "context": "event", "errorCode": 2, "errorText": "seloger", "tile_type": "person" } ] } ] }, { "name": "Leaders", "displayOrder": 1, "groups": [{ "type": "static", "displayOrder": 1, "tiles": [{ "context": "event", "dataStamp": 1535184247, "eventId":123 "tile_type": "static" } ] } ] } ] }] errorCode键。 如果图块对象不包含任何“ errorText”或“ errorCode”键,则图块项包含必填字段“ errorCode”。

为验证上述条件,我定义了如下所示的模式。但是它不起作用。我的模式出了什么问题。

errorText

1 个答案:

答案 0 :(得分:1)

var snapshot = await query.once(); var result = snapshot.value.values as Iterable; for(var item in result) { print(item); } 中的if语句缺少required

properties

如果没有 "if": { "properties": { "tile_type": { "enum": ["person"] }, "errorCode": { "enum": [2, 10] }, "required": ["errorCode"] } }, ,则只有设置了属性后,该属性的值才会生效。因此,原始的required模式将传递没有iftile_type的任何对象。

https://stackoverflow.com/a/51034071/329463可能会给您一些启发,以构建专有属性集群。

编辑:已修改的完整架构

errorCode