jsonschema

How to define a JSON schema that requires at least one of many properties

北城余情 提交于 2019-12-01 15:35:25
I would like to know if I can define a JSON schema (draft 4) that requires at least one of many properties possible for an object. I already know of allOf , anyOf and oneOf but just can't figure out how to use them in the way I want. Here are some example JSON to illustrate : // Test Data 1 - Should pass { "email": "hello@example.com", "name": "John Doe" } // Test Data 2 - Should pass { "id": 1, "name": "Jane Doe" } // Test Data 3 - Should pass { "id": 1, "email": "hello@example.com", "name": "John Smith" } // Test Data 4 - Should fail, invalid email { "id": 1, "email": "thisIsNotAnEmail",

jsonSchema attribute conditionally required depends on parent object

大城市里の小女人 提交于 2019-12-01 09:01:49
问题 Per this question jsonschema attribute conditionally required, I can apply conditional required properties. However, it can only depend on the properties on the same level of object. In certain case, I want to one property required depend on its parent object property, is it possible? For the below example: { type: 'object', properties: { { os: { type: 'string', enum: ['macOs', 'windows'] }, specs: { macModel: { type: 'string', enum: ['macbook air', 'macbook pro', 'macbook'] }, memory: { type

JsonSchema: Validate type based on value of another property

自古美人都是妖i 提交于 2019-12-01 06:50:29
I am using the following schema to validate my json: { "$schema": "http://json-schema.org/schema#", "title": " Rules", "description": "Describes a set of rules", "type": "object", "properties": { "rules": { "type": "array", "items": { "type": "object", "properties": { "precedence": { "type": "number", "minimum": 0 }, "conditions": { "type": "array", "items": { "type": "object", "properties": { "field": { "type": "string", "enum": [ "Name", "Size" ] }, "relation": { "type": "string", "enum": [ "is", "is not", "is not one of", "is one of" ] }, "value": { "type": ["array", "string", "number"] } }

Mutually exclusive property groups

时光毁灭记忆、已成空白 提交于 2019-12-01 05:57:50
Suppose I have an object with four possible properties: a, b, c, d. a and b can only appear together (i.e., a appears if and only if b appears). If a and b appear, c cannot appear (that is, a/b and c are mutually exclusive). If a and b do not appear, c may appear (but is not required to). d can appear in any combination with a/b, c, or on its own. No properties other than a, b, c, or d may appear at all. How do I express this as a jsonschema? I suspect I could use some combination of oneOf and required , but I can't figure out the proper incantation. You can phrase your constraints as: either:

JSON schema : “allof” with “additionalProperties”

亡梦爱人 提交于 2019-11-30 11:58:33
问题 Suppose we have schema following schema (from tutorial here): { "$schema": "http://json-schema.org/draft-04/schema#", "definitions": { "address": { "type": "object", "properties": { "street_address": { "type": "string" }, "city": { "type": "string" }, "state": { "type": "string" } }, "required": ["street_address", "city", "state"] } }, "type": "object", "properties": { "billing_address": { "$ref": "#/definitions/address" }, "shipping_address": { "allOf": [ { "$ref": "#/definitions/address" },

Make sure item property in array is unique in Json Schema?

狂风中的少年 提交于 2019-11-30 10:55:09
Given the following JSON schema, is it possible to indicate that the "name" property shall be unique (i.e. there should NOT be two items with the same "name" in the "elements" array. { "root": { "type": "object", "properties": { "elements": { "type": "array", "minItems": 1, "items": { "type": "object", "properties": { "name": { "type": "string", "title": "Element Name", "minLength": 3, }, "url": { "type": "string", "title": "Some URL" } } } } } } } I tried to use the uniqueItems keyword but it seems it was designed for simple lists of values. No, it is not possible. From the docs, json-schema:

How to programmatically validate Json string against a Json schema in Java? [closed]

爱⌒轻易说出口 提交于 2019-11-30 10:01:40
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed last year . I want to validate the format and structure of a JSON object against its JSON schema using Java. Where can I begin? 回答1: If you're looking for an online tool then you can try jsonschemalint-online-validator If you need to validate it using Java code then validate-json-against-schema-in-java should help. It

JSON schema for dynamic properties

时光毁灭记忆、已成空白 提交于 2019-11-30 08:28:35
问题 i have an object in which the "key" of the property will be set dynamically... what is the right way of defining this in a JSON Schema? This is what my object looks like { "column_definitions": [ { "Field_1": { "type": "Numeric", "isNullable": false } }, { "Field_2": { "type": "Boolean", "isNullable": true } } ], "row_values": [ ... ] } The "key" of the "column_definitions" will always be dynamic (it can be "Field_1" just as much as it can be "Field_24" What is the proper to define this in

Understanding the “additionalProperties” keyword in JSON Schema draft version 4

扶醉桌前 提交于 2019-11-30 05:59:31
Link to the specification: http://json-schema.org/latest/json-schema-validation.html#anchor64 Section 5.4.4.2 states: Successful validation of an object instance against these three keywords depends on the value of "additionalProperties": if its value is boolean true or a schema, validation succeeds; ... Section 5.4.4.3 states: If "additionalProperties" is absent, it may be considered present with an empty schema as a value. Ok, so if "additionalProperties" is absent, it counts as being present with an empty schema. And if it's a schema (of any kind), then the object validates successfully

JSON Schema - require all properties

被刻印的时光 ゝ 提交于 2019-11-30 04:27:35
The required field in JSON Schema JSON Schema features the properties , required and additionalProperties fields. For example, { "type": "object", "properties": { "elephant": {"type": "string"}, "giraffe": {"type": "string"}, "polarBear": {"type": "string"} }, "required": [ "elephant", "giraffe", "polarBear" ], "additionalProperties": false } Will validate JSON objects like: { "elephant": "Johnny", "giraffe": "Jimmy", "polarBear": "George" } But will fail if the list of properties is not exactly elephant, giraffe, polarBear . The problem I often copy-paste the list of properties to the list of