specify a value can be a string or null with json schema

℡╲_俬逩灬. 提交于 2019-12-03 23:27:36
Explosion Pills

From http://json-schema.org/latest/json-schema-validation.html#anchor79

The value of this keyword MUST be either a string or an array. If it is an array, elements of the array MUST be strings and MUST be unique.

String values MUST be one of the seven primitive types defined by the core specification.

Then we refer to types: http://json-schema.org/latest/json-schema-core.html#anchor8

It lists string and null. Try:

"member_region": { "type": "string, null" }

Extending on Explosion Pills answer if you go for the array syntax:

"member_region": { "type": [ "string", "null" ] } // this works

because you are stating a type not an example you shouldn't go for:

 "member_region": { "type": [ "string", null ] } // this throws an exception
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!