Questions tagged [jsonschema]

A JSON Schema is a JSON document (an object) which defines constraints on what other JSON documents (the instances) should obey; it can also be used to interpret instances so as to provide links to external resources (hyper schema).

JSON (JavaScript Object Notation) Schema defines the media type application/schema+json, a JSON based format for defining the structure of JSON data.

JSON Schema provides a contract for what JSON data is required for a given application and how to interact with it. JSON Schema is intended to define validation, documentation, hyperlink navigation, and interaction control of JSON data.

References:

For the latest Internet Draft documents, see the specification section of the website.

3348 questions
67
votes
3 answers

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

I want to make a schema of json file.It's for an array of products. The json schema is similar as below: { "$schema": "http://json-schema.org/draft-04/schema#", "title": "Product set", "type": "array", "items": { "title": "Product", "type":…
Stella
  • 1,197
  • 1
  • 10
  • 18
65
votes
3 answers

JSON Schema with unknown property names

I want to have a JSON Schema with unknown property names in an array of objects. A good example is the meta-data of a web page: "meta": { "type": "array", "items": { "type": "object", "properties": { …
Thami Bouchnafa
  • 1,987
  • 1
  • 15
  • 21
60
votes
7 answers

JSON Schema - require all properties

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"}, …
Adam Matan
  • 128,757
  • 147
  • 397
  • 562
57
votes
4 answers

Generate JSON schema from Java class

I have a POJO class: public class Stock { int id; String name; Date date; } Are there any annotations or development framework/API that can convert POJO to JSON schema like below: {"id": { "type" : "int" …
user3587174
  • 661
  • 3
  • 8
  • 13
57
votes
2 answers

Json Schema example for oneOf objects

I am trying to figure out how oneOf works by building a schema which validates two different object types. For example a person (firstname, lastname, sport) and vehicles (type, cost). Here are some sample objects: {"firstName":"John",…
Stanimirovv
  • 3,064
  • 8
  • 32
  • 56
56
votes
3 answers

What is the difference between "required" vs "optional" in JSON Schema

Sometimes, I noticed the following JSON Schemas: { "type": "object", "properties": { "address": { "type": "string", "required": true } } } vs { "type": "object", …
Cory
  • 14,865
  • 24
  • 57
  • 72
55
votes
1 answer

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

Suppose that I have schema like fname: string lname: string age: string None of them are required. User can send me any of those attributes above but nothing else that is not declared. They can pass me fname, lname and age or all. But if they pass…
Tuan Anh Tran
  • 6,807
  • 6
  • 37
  • 54
51
votes
4 answers

Generating JSON schema from C# class

Is there any way to programmatically generate a JSON schema from a C# class? Something which we can do manually using http://www.jsonschema.net/
Ravi Gupta
  • 6,258
  • 17
  • 56
  • 79
50
votes
2 answers

How to extend a schema in JSON schema?

I'm using JSON schema for data modelling. I define a base Document schema, that I later use to define model schemas (e.g. Product, Category, User, etc.). I'm doing this because I want all models to inherit certain structure/rules. For example every…
Panagiotis Panagi
  • 9,927
  • 7
  • 55
  • 103
50
votes
1 answer

Dictionary-like JSON schema

I have a json object that can contain any number of nested objects with certain specification, for example: { "Bob": { "age": "42", "gender": "male" }, "Alice": { "age": "37", "gender": "female" } } And would like to have a…
ironic
  • 8,368
  • 7
  • 35
  • 44
50
votes
3 answers

How would you design JSON Schema for an arbitrary key?

I have the following JSON output data: { "label_name_0" : 0, "label_name_5" : 3, . . . "label_name_XXX" : 4 } The output is simple: a key[1] name associated with integer value. If the key name doesn't change, I can easily come up…
Cory
  • 14,865
  • 24
  • 57
  • 72
49
votes
4 answers

JSON Schema - specify field is required based on value of another field

Wondering if this is possible with schema draft 03. I've gotten dependencies working elsewhere, I think there is possibly just some creative use of them required in order to use them for specifying the required property of some field. My current…
pospi
  • 3,540
  • 3
  • 27
  • 26
47
votes
5 answers

JSON schema - valid if object does *not* contain a particular property

Is it possible to set up a JSON schema that still allows for additionalProperties but does not match if a very particular property name is present? In other words, I need to know if it's possible to have the exact opposite of the required…
M Miller
  • 5,364
  • 9
  • 43
  • 65
45
votes
1 answer

How to manage multiple JSON schema files?

I'm trying to validate my JSON API using node.js + json-schema.js from commonjs-utils. Just single validation was easy but could not find right way how to manage multiple schema files to enable referencing each other. Suppose that I got two Models &…
Ray Yun
  • 1,571
  • 3
  • 16
  • 22
45
votes
4 answers

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

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": { …
begie
  • 1,194
  • 1
  • 11
  • 23