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
8
votes
1 answer

How to make a two dimensional array in JSON Schema?

How would you write the following two dimensional array in JSON schema? The grid is fixed to 16*13. It contains completely empty rows or row with values like int(0-99) or an empty string. Here is an example of the array: [ [], [], [], …
Jelle
  • 513
  • 2
  • 5
  • 8
8
votes
3 answers

Jackson: generate schemas with references

When using Jackson's JSON schema module, instead of serializing the complete graph I'd like to stop whenever one of my model classes is encountered, and use the class name to insert a $ref for another schema. Can you guide me to the right place in…
dnault
  • 8,340
  • 1
  • 34
  • 53
8
votes
2 answers

JSON schema for data description vs data validation vs input validation

In what I can find about using JSON schema, there seems to be a confusing conflation of (or at least a lack of distinction among) the tasks of describing valid data, validating stored data, and validating input data. A typical example looks…
mmr
  • 134
  • 3
  • 7
7
votes
0 answers

convert json schema to avro schema in python

I want to convert json schema to avro schema using python because I'm building my microservice in Python Fastapi. json-schema { "type":"object", "properties":{ "IsNonPO":{ "title":"IsNonPO", "type":[ …
Isan Sahoo
  • 384
  • 2
  • 10
7
votes
1 answer

OpenApi v3: additionalProperties false with referenced schemas

There is some questions around this topic, but I dind't find the right way to do it. What I want is to define all parameters in a single place and reuse it with no need to write it again. I already get that by using "allOf", but this limited the use…
7
votes
3 answers

user-friendly error message using ajv json schema validator

Assuming I have the schema & JSON: JSON Schema: const schema = { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "required": [ "countries" ], "definitions": { "europeDef": { "type": "object", …
user8479984
  • 451
  • 2
  • 9
  • 23
7
votes
3 answers

A single source of truth for API request/response shapes, including JSON schema, TypeScript types, and runtime validators?

I'm writing a typical Node.js REST service with endpoints that receive JSON input (as POST bodies) and return JSON responses. I want these three things: JSON schemas defining the shapes of request bodies and response bodies for my endpoints. (Or…
callum
  • 34,206
  • 35
  • 106
  • 163
7
votes
1 answer

How to reference schema of json which is top level array

I have a JSON file which contains a list of items. The only thing stored in this file is the items as a array. e.g: [ {...}, {...}, {...}, ] I want to define a schema file for this. This seems fine as the initial type can be set to…
Ben
  • 3,160
  • 3
  • 17
  • 34
7
votes
3 answers

Use conditional statements on json schema based on another schema object

I have a json object like: { "session": { "session_id": "A", "start_timestamp": 1535619633301 }, "sdk": { "name": "android", "version": "21" } } The sdk name can either be android or ios. And the session_id is based on name…
user2565192
  • 694
  • 1
  • 8
  • 19
7
votes
1 answer

JSON Schema `required` allows empty string for value

I'm using a JSON schema template to validate the data that is received by an online form. One of the requirements of the validator is that it allows some questions to be required based on the answers given for other questions. For example if the…
Jake12342134
  • 1,539
  • 1
  • 18
  • 45
7
votes
1 answer

JSON Schema property dependent on value of previous property

I'd like to be able to write JSON schema code that allows one property's value to be dependent on the value of another property. More specifically, I have two questions A and B. Question B's answer can only be not null when question A has a…
user10623303
7
votes
1 answer

How to specify defaults conditionally with JSON Schema

I have a field status. If the user is setting the job as draft status I don't want to require the description field - but I DO want to to have a default of empty string. If the user is publishing the job than I want the description to be…
nwkeeley
  • 1,397
  • 5
  • 18
  • 28
7
votes
4 answers

Validate datetime value using python jsonschema

I'm using jsonschema to validate my python dictionary. I' trying to validate a datetime value but I'm not sure how to do it. Here's what I have so far, which results in an error because jsonschema doesn't have a datetime type: order = { "name":…
Johnny Metz
  • 5,977
  • 18
  • 82
  • 146
7
votes
1 answer

What is the difference between items and properties in jsonschema?

I'm just learning jsonschema. It's not clear to me what the difference is between items and properties. Can someone please explain?
jlconlin
  • 14,206
  • 22
  • 72
  • 105
7
votes
1 answer

How to validate a JSON object against a JSON schema based on object's type described by a field?

I have a number of objects (messages) that I need to validate against a JSON schema (draft-04). Each objects is guaranteed to have a "type" field, which describes its type, but every type have a completely different set of other fields, so each type…
MaxEd
  • 360
  • 1
  • 10