JSON Schema for Dynamic Properties

I have an object in which the "key" of the property will be set dynamically ... What is the correct way to define 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" in the "column_definitions" parameters will always be dynamic (it can be "Field_1" in the same way as "Field_24"

How to correctly define this in a JSON schema?

I donโ€™t want to just say "type": "object" because I want to be able to define the static properties of "type" and "isNullable". In addition, I cannot use "oneOf" simply because I donโ€™t know what it can be the "key" and there are no established values โ€‹โ€‹of potential.

This is what I still have:

 { "$schema": "http://json-schema.org/draft-04/schema", "title": "SomeSchema", "description": "SomeDescription", "type": "object", "properties": { "column_definitions": { "type": ["array", "null"], "items": { "$ref": "#/definitions/columnDef" }, "readOnly": true }, "row_values": { "type": ["array", "null"], "items": { "type": "object" }, "readOnly": true } }, "definitions": { "columnDef" : { "type": "object", "properties": { "THIS_IS_MY_DYNAMIC_PROPERTY": { "type": "object", "properties": { "type": { "type" : ["string", "null"], "enum": ["Text", "Boolean", "Numeric", "DateTime"], "readOnly": true }, "isNullable": { "type" : ["boolean", "null"], "readOnly": true } } } } } } } 
+7
json properties schema jsonschema
source share
1 answer

I think you are looking for a patternProperties field, not properties . It should look something like this, assuming you just want a match for the whole pattern:

 { "$schema": "http://json-schema.org/draft-04/schema", "title": "SomeSchema", "description": "SomeDescription", "type": "object", "properties": { "column_definitions": { "type": [ "array", "null" ], "items": { "$ref": "#/definitions/columnDef" }, "readOnly": true }, "row_values": { "type": [ "array", "null" ], "items": { "type": "object" }, "readOnly": true } }, "definitions": { "columnDef": { "type": "object", "patternProperties": { ".*": { "type": "object", "properties": { "type": { "type": [ "string", "null" ], "enum": [ "Text", "Boolean", "Numeric", "DateTime" ], "readOnly": true }, "isNullable": { "type": [ "boolean", "null" ], "readOnly": true } } } } } } } 
+9
source share

All Articles