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
250
votes
12 answers

Tool to generate JSON schema from JSON data

We have this json schema draft. I would like to get a sample of my JSON data and generate a skeleton for the JSON schema, that I can rework manually, adding things like description, required, etc, which can not be infered from the specific…
blueFast
  • 41,341
  • 63
  • 198
  • 344
169
votes
3 answers

jsonSchema attribute conditionally required

In jsonSchema you can indicate whether defined fields are mandatory or not using the "required" attribute: { "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "properties": { "header": { "type":…
tom redfern
  • 30,562
  • 14
  • 91
  • 126
150
votes
4 answers

Specify a value can be a string or null with JSON Schema

Hopefully this isn't obvious to others because I find the docs at https://json-schema.org/ to be lacking in finer details. I'm getting a block of JSON with some properties that can be null or a string. How do you specify, in a JSON Schema (to be…
evanmcdonnal
  • 46,131
  • 16
  • 104
  • 115
146
votes
2 answers

Correct way to define array of enums in JSON schema

I want to describe with JSON schema array, which should consist of zero or more predefined values. To make it simple, let's have these possible values: one, two and three. Correct arrays (should pass validation): [] ["one", "one"] ["one",…
senasi
  • 1,564
  • 2
  • 11
  • 12
129
votes
6 answers

Json Schema file extension

Is there any naming convention for a json schema file extension? XML has .xsd (XML Schema Definition), what should json schema files have, .jsd (JSON Schema Definition)?
Fresa
  • 1,411
  • 2
  • 10
  • 8
119
votes
3 answers

Only allow properties that are declared in JSON schema

I am using json-schema and wanting to only allow properties that are declared in this file to pass validation. For instance if a user passes a "name" property in their json object it will fail this schema because "name" is not listed here as a…
ipengineer
  • 3,107
  • 7
  • 33
  • 37
118
votes
4 answers

How do I require one field or another or (one of two others) but not all of them?

I am having trouble coming up with a JSON schema that will validate if the JSON contains either: one field only another field only (one of two other fields) only but not to match when multiples of those are present. In my case specifically, I want…
user3486184
  • 2,147
  • 3
  • 26
  • 28
99
votes
3 answers

How to define UUID property in JSON Schema and Open API (OAS)

When using JSON Schema and Open API specification (OAS) to document a REST API, how do I define the UUID property?
Slava Fomin II
  • 26,865
  • 29
  • 124
  • 202
88
votes
8 answers

How to generate JSON-Schema from Swagger API Declaration

I have Swagger API Declaration for services using Swagger v 1.2. My original feeling about Swagger was that it is very close to JSON Schema (Draft 3 and lately Draft 4) and it shall be relatively easy to generate JSON Schema for request and response…
Jan Vlcinsky
  • 42,725
  • 12
  • 101
  • 98
84
votes
8 answers

Generate C# classes from JSON Schema

I'm creating a C# WCF Web Service that return a lot of data in a JSON format. The client is an iPad application that is currently being developped by another team, So I'm working on specifications, without example data. Currently the JSON string is…
Julien N
  • 3,880
  • 4
  • 28
  • 46
82
votes
5 answers

Generate Json schema from XML schema (XSD)

Does anybody know how to generate a JSON schema from a existing XML schema (XSD file)? Are there any tools available for this?
JB Hurteaux
  • 4,428
  • 6
  • 32
  • 35
82
votes
5 answers

JSON schema : "allof" with "additionalProperties"

Suppose we have schema following schema (from tutorial here): { "$schema": "http://json-schema.org/draft-04/schema#", "definitions": { "address": { "type": "object", "properties": { "street_address": { "type": "string"…
lm.
  • 4,033
  • 4
  • 25
  • 37
70
votes
5 answers

Validating JSON against Swagger API schema

I created an API spec from some JSON files and I am trying to test if the files validate against the API spec. There are some good tools to validate against JSON Schema, but I did not have chance to find a tool to validate against specs created in…
Peter G.
  • 7,816
  • 20
  • 80
  • 154
69
votes
1 answer

JSON Schema definition for array of objects

I've seen this other question but it's not quite the same, and I feel like my issue is simpler, but just isn't working. My data would look like this: [ { "loc": "a value 1", "toll" : null, "message" : "message is sometimes null"}, { "loc":…
Kyle Falconer
  • 8,302
  • 6
  • 48
  • 68
68
votes
2 answers

How to define a JSON schema that requires at least one of many properties

I would like to know if I can define a JSON schema (draft 4) that requires at least one of many properties possible for an object. I already know of allOf, anyOf and oneOf but just can't figure out how to use them in the way I want. Here are some…
MaxiWheat
  • 6,133
  • 6
  • 47
  • 76
1
2 3
99 100