How would you design JSON Schema for an arbitrary key?

On json-schema.org you will find something appropriate in the File System Example section. You can define patternProperties inside an object. { “type”: “object”, “properties”: { “/”: {} }, “patternProperties”: { “^(label_name_[0-9]+)+$”: { “type”: “integer” } }, “additionalProperties”: false, } The regular expression (label_name_[0-9]+)+ should fit your needs. In JSON Schema regular expressions are explicitly anchored … Read more

Generating JSON schema from C# class

Another option which supports generating JSON Schema v4 is NJsonSchema: var schema = JsonSchema.FromType<Person>(); var schemaJson = schema.ToJson(); The library can be installed via NuGet. Update for NJsonSchema v9.4.3+: using NJsonSchema; var schema = await JsonSchema.FromTypeAsync<Person>(); var schemaJson = schema.ToJson();

Json Schema example for oneOf objects

Try this: { “description” : “schema validating people and vehicles”, “type” : “object”, “oneOf” : [ { “type” : “object”, “properties” : { “firstName” : { “type” : “string” }, “lastName” : { “type” : “string” }, “sport” : { “type” : “string” } } }, { “type” : “object”, “properties” : { “vehicle” : … Read more

Generate JSON schema from Java class

EDIT: as pointed out by commenters, module is being deprecated, not maintained. So, Caveat Emptor etc One such tool is Jackson JSON Schema module: https://github.com/FasterXML/jackson-module-jsonSchema which uses Jackson databind’s POJO introspection to traverse POJO properties, taking into account Jackson annotations, and produces a JSON Schema object, which may then be serialized as JSON or used … Read more

Json Schema validation: do not allow fields other than those declared in schema [duplicate]

You can create a json-schema and use the option: additionalProperties = false That way you only allow the attributes defined in properties. In your case: { “properties”: { “fname”: {“type”: “string”}, “lname”: {“type”: “string”}, “age”: {“type”: “string”} }, “additionalProperties”: false }

JSON Schema – require all properties

You can just use the “minProperties” property instead of explicity naming all the fields. { “type”: “object”, “properties”: { “elephant”: {“type”: “string”}, “giraffe”: {“type”: “string”}, “polarBear”: {“type”: “string”} }, “additionalProperties”: false, “minProperties”: 3 }

JSON Schema with unknown property names

Use patternProperties instead of properties. In the example below, the pattern match regex .* accepts any property name and I am allowing types of string or null only by using “additionalProperties”: false. “patternProperties”: { “^.*$”: { “anyOf”: [ {“type”: “string”}, {“type”: “null”} ] } }, “additionalProperties”: false … or if you just want to allow … Read more

How to define the min size of array in the json schema

To set the minimum # of item in an array, use the “minItems”. See: https://datatracker.ietf.org/doc/html/draft-fge-json-schema-validation-00#section-5.3.3 and http://jsonary.com/documentation/json-schema/?section=keywords/Array%20validation { “$schema”: “http://json-schema.org/draft-04/schema#”, “title”: “Product”, “description”: “A product from Acme’s catalog”, “type”: “object”, “properties”: { … “tags”: { “type”: “array”, “items”: { “type”: “string” }, “minItems”: 1, “maxItems”: 4, “uniqueItems”: true } }, “required”: [“id”, “name”, “price”] }

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)