jsonschema

JSON schema for data description vs data validation vs input validation

笑着哭i 提交于 2019-12-10 03:26:56
问题 In what I can find about using JSON schema, there seems to be a confusing conflation of (or at least a lack of distinction among) the tasks of describing valid data, validating stored data, and validating input data. A typical example looks like: var schema = { type: 'object', properties: { id: { type: 'integer', required: true }, name: { type: 'string', required: true }, description: { type: 'string', required: false } } }; This works well for describing what valid data in a data store

JSON Schema - how do I specify that a boolean value must be false?

微笑、不失礼 提交于 2019-12-10 00:45:22
问题 Let's say I have a type that will be boolean, but I don't just want to specify that it will be boolean, I want to specify that it will have the value false. To just specify that it will be boolean I do the following: { "properties": { "some_flag": { "type": "boolean" } } } I have tried substituting "boolean" above for "false" and false (without quotes), but neither works. 回答1: Use the enum keyword: { "properties": { "some_flag": { "enum": [ false ] } } } This keyword is designed for such

How to generate JSON schema from a JAXB annotated class?

╄→гoц情女王★ 提交于 2019-12-09 18:58:26
问题 I have a entity class looks like this. @XmlRootElement public class ImageSuffix { @XmlAttribute private boolean canRead; @XmlAttribute private boolean canWrite; @XmlValue; private String value; } And I'm using following dependency for JSON generation. <dependency> <groupId>com.fasterxml.jackson.jaxrs</groupId> <artifactId>jackson-jaxrs-json-provider</artifactId> <version>2.1.4</version> </dependency> When I tried with following code, (which referred from Generating JSON Schemas with Jackson)

JSON schema anyOf validation based on one of properties

自古美人都是妖i 提交于 2019-12-09 17:05:07
问题 I'm having difficulty figuring out how to validate an array of objects based on the value of one of the properties. So where I have a JSON object like: { "items": [ { "name": "foo", "otherProperty": "bar" }, { "name": "foo2", "otherProperty2": "baz", "otherProperty3": "baz2" }, { "name": "imInvalid" } ] } I would like to say that items can contain anyOf objects where name can be "foo" or "foo2" if it's "foo" then the only valid other property (required) is "otherProperty" if the name is "foo2

Correct way to define array of enums in JSON schema

99封情书 提交于 2019-12-09 14:00:12
问题 I want to describe with JSON schema array, which should consist of zero or more predefined values. To make it simple, let's have these possible values: one , two and three . Correct arrays (should pass validation): [] ["one", "one"] ["one", "three"] Incorrect: ["four"] Now, I know the "enum" property should be used, but I can't find relevant information where to put it. Option A (under "items" ): { "type": "array", "items": { "type": "string", "enum": ["one", "two", "three"] } } Option B: {

Conditional Json Schema validation based on property value

百般思念 提交于 2019-12-09 13:37:36
问题 I have the input json like below, { "results": [ { "name": "A", "testA": "testAValue" } ] } the condition is, if value of 'name' is 'A', then 'testA' should be the required field and if value of 'name' is 'B', then 'testB' should be the required field. This is the Json Schema I tried and its not working as expected, { "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "required": [ "results" ], "properties": { "results": { "type": "array", "oneOf": [ { "$ref": "#

How to make anyOf a set of multually exclusive properties except one

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-09 11:56:39
问题 I have a legacy API I'm trying to define in a JSON Schema and the object has a weird structure where there are a set of 4 properties, any one of them is required, and 3 of them are mutually exclusive. The are a more than 30 shared optional properties after that as well, I'll note them as ... . e.g., { "foo": "bar", "baz": 1234, ... } // OK { "foo": "bar", "buzz": 1234, ... } // OK { "foo": "bar", "fizz": 1234, ... } // OK { "foo": 1234, ... } // OK { "baz": 1234, ... } // OK { ... } // NOT OK

JSON schema validation with arbitrary keys

六眼飞鱼酱① 提交于 2019-12-08 23:39:09
问题 I am using validictory for validating the attached JSON data and schema. Working so far. However the data dictionary can have arbitrary string keys (others than 'bp' but). The key 'bp' in the schema here is hard-coded...it can be a string from a given list (enum of string). How do I add the enum definition here for the "first level" of the dict. import json import validictory data = {'bp': [{'category': 'bp', 'created': '2013-03-08T09:14:48.148000', 'day': '2013-03-11T00:00:00', 'id':

json schema property description and “$ref” usage

做~自己de王妃 提交于 2019-12-08 16:21:05
问题 I am writting a json schema to validate my json outputs produced by an exe.The schema being little bit complexe, I have defined some "definitions" that are referenced in properties ("$ref": "#/definitions/...). And using definitions here is all the more important because I have a case where the definition is recursive. My schema now works well, it validates correctly my json outputs. Now, I am trying to document the schema correctly using "description" keyword for each property. To develop

How to find parent Json node while parsing a JSON

孤街浪徒 提交于 2019-12-08 16:13:52
问题 I am parsing a JSON Stream using Jackson. API that I am using is ObjectMapper.readTree(..) Consider following stream: { "type": "array", "items": { "id": "http://example.com/item-schema", "type": "object", "additionalProperties": {"$ref": "#"} } } Now when I read additionalProperties, I figure out there is a "$ref" defined here. Now to resolve the reference, I need to go to its parent and figure out the id (to resolve the base schema). I can't find any API to go to parent of JsonNode holding