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
45
votes
4 answers

Convert a JSON schema to a python class

Is there a python library for converting a JSON schema to a python class definition, similar to jsonschema2pojo -- https://github.com/joelittlejohn/jsonschema2pojo -- for Java?
JD White
  • 807
  • 1
  • 10
  • 15
44
votes
1 answer

Understanding the "additionalProperties" keyword in JSON Schema draft version 4

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…
Hammerite
  • 21,755
  • 6
  • 70
  • 91
44
votes
5 answers

Correct JSON Schema for an array of items of different type

I have an unordered array of JSON items. According to the specification https://datatracker.ietf.org/doc/html/draft-zyp-json-schema-03#section-5.5 the json schema below will only validate if the objects in the array appear IN THAT ORDER. I don't…
deepwinter
  • 4,568
  • 2
  • 31
  • 37
43
votes
6 answers

json schema date-time does not check correctly

I have a JSON and a JSON-schema JSON: { "aaa": "4000-02-01 00:00:00" } JSON-schema: { "$schema": "http://json-schema.org/draft-04/schema", "type": "object", "properties": { "aaa": { "type": "string", …
JoachimR
  • 5,150
  • 7
  • 45
  • 50
43
votes
2 answers

Using RegEx in JSON Schema

Trying to write a JSON schema that uses RegEx to validate a value of an item. Have an item named progBinaryName whose value should adhrere to this RegEx string "^[A-Za-z0-9 -_]+_Prog\\.(exe|EXE)$". Can not find any tutorials or examples that…
Destroyer
  • 639
  • 1
  • 7
  • 13
42
votes
1 answer

Why is JOI more popular than AJV?

I am deciding on a validation library that I can use for both client and server side validation. I have been comparing JOI (+ joi-browser) and AJV. As I understand it JOI and AJV can accomplish the same things. AJV can even perform async validation…
tkalis
  • 557
  • 1
  • 5
  • 5
40
votes
3 answers

How to specify a property as null or a reference?

I have a json document in which a part can be either null or a subobject, like this: [{ "owner":null }, { "owner":{ "id":1 } }] The question is if its possible to model this in json schema draft v4 using ref? What I would…
viblo
  • 4,159
  • 4
  • 20
  • 28
39
votes
2 answers

JSON Schema: validate a number-or-null value

Is there a way to enable a JSON schema property to be either a number or null? I am building an API which contains a heading attribute. Can be a number between 0 (inclusive) and 360 (exclusive), or null, so the following inputs are OK: {"heading":…
Adam Matan
  • 128,757
  • 147
  • 397
  • 562
39
votes
2 answers

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

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": { …
tadasajon
  • 14,276
  • 29
  • 92
  • 144
38
votes
4 answers

How do I configure VS Code to enable code completion on .json files (jsonschema support)?

In the Visual Stuido Code demo minute 28:57-29:20 and 30:20-31:10, some cool JSON code completion is shown. Where and how do I add a schema for my JSON files to a project? How does VS Code know which schema to use for a given .json file?
Michael_Scharf
  • 33,154
  • 22
  • 74
  • 95
38
votes
3 answers

JSON Schema validation in PostgreSQL?

I can't find any information about JSON schema validation in PostgreSQL, is there any way to implement JSON Schema validation on PostgreSQL JSON data type?
khorvat
  • 1,630
  • 2
  • 20
  • 31
37
votes
1 answer

How to use JSON Schema to require one of two fields

I want to validate JSON to make one of two fields manadatory. Let's assume we have two fields (Email Address and Phone Number). I want to make sure that one of the two fields is required for the record to be valid. { "$schema":…
Jolly
  • 371
  • 1
  • 3
  • 3
36
votes
5 answers

JSON Schema to check date of YYYY-MM-DD

Could someone tell me JSON Schema Validation for accepting date of YYYY-MM-DD format alone? My sample JSON: {"data1" : "foo", "date" :"2016-11-24"}
user6543599
  • 541
  • 2
  • 8
  • 18
35
votes
1 answer

JSON Schema regarding use of $ref

I understand that $ref takes a URI to a json schema to use but where does $ref : "#" point to? Does it just mean use the current schema for this block level? Or does it mean to use the root level schema defined in the root level id? Thanks EDIT: So…
hunterc
  • 1,957
  • 2
  • 15
  • 18
34
votes
7 answers

JSON schema validation

Is there a stable library that can validate JSON against a schema? json-schema.org provides a list of implementations. Notably C and C++ are missing. Is there a reason I can't easily find a C++ JSON schema validator? Doesn't anyone else want a…
deft_code
  • 57,255
  • 29
  • 141
  • 224