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
10
votes
3 answers

How do I validate a string using a regular expression with Ajv?

I'm trying to validate a string(Phone number) with this regex ^+[0-9]{9,12}$ but I get this error ... .pattern should match format "regex" ... I've been through the documentation at https://ajv.js.org etc. looked at examples etc. and tried a lot of…
LegionDev
  • 1,391
  • 4
  • 15
  • 29
10
votes
0 answers

How to convert json schema to avro schema

My application has been using json schema (org.everit.json.schema.Schema ) to validate JSON messages whether they comply to a particular format. We are now thinking of moving to the Avro schema. This involves converting previously-stored schema.json…
user2206366
  • 461
  • 3
  • 6
  • 17
10
votes
3 answers

Unclear about the meaning of propertyNames

Here is a JSON schema that uses propertyNames: { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "propertyNames": {"enum": ["num", "name"]} } I "think" the meaning of that schema is this: A conforming JSON…
Roger Costello
  • 3,007
  • 1
  • 22
  • 43
10
votes
2 answers

Slim - modify POST request body inside middleware

I am using Slim v3 and the json schema validator by justinrainbow for my API. What I want to do and just can't get to work is: in the middleware: validate incoming json with defaults. this produces a modified object write the modified object back…
tscherg
  • 1,032
  • 8
  • 22
10
votes
1 answer

How do I define a Json Schema containing definitions, in code

I am attempting to replicate the following Json Schema example, by defining the schema in code using Newtonsoft.Json.Schema: { "$schema": "http://json-schema.org/draft-04/schema#", "definitions": { "address": { "type": "object", …
Kit
  • 2,089
  • 1
  • 11
  • 23
10
votes
2 answers

json-schema: how to transform from one json-schema to another

I have the two different json-schemas: schemaA -> A calendar as defined at http://json-schema.org/calendar { "$schema": "http://json-schema.org/draft-04/schema#", "description": "A representation of an event", "type": "object", …
user6614015
  • 101
  • 1
  • 1
  • 5
10
votes
1 answer

Testing two versions of json-schema for backwards compatibility

I have a repository that contains versioned json-schemas so for each type of schema I could have several revisions: v1, v2, v3 etc. I want to test schemas for backwards compatibility, so that any event which was valid for v1 schema is guaranteed to…
Petr
  • 5,999
  • 2
  • 19
  • 25
10
votes
1 answer

enforce empty JSON schema

I want a JSON schema that enforces an empty JSON object, e.g. {} Is this a good idea and possible? I tried the following but it allows me to enter anything in the JSON body: { "description": "voice mail record", "type": "object", …
AwkwardCoder
  • 24,893
  • 27
  • 82
  • 152
10
votes
1 answer

JSON schema reference another element in the document

Is there a way to express reference to another element in the same JSON document using JSON schema? The title might be a bit confusing, but i'm not looking for the "$ref" attribute, which references another type, but I'm curious, if there is a way,…
Balázs Édes
  • 13,452
  • 6
  • 54
  • 89
10
votes
2 answers

Is it possible in json schema to define a constraint between two properties

I have two fields in my schema - one is a required property called "name" and the other is optional (used to define a sorting property) called "nameSort" and I want to express If the "nameSort" field is defined, the "name" field should also be…
kellyfj
  • 6,586
  • 12
  • 45
  • 66
10
votes
1 answer

What is the Correct way to define key-value pairs in json schema

How do i define key value pairs object in json schema (the "correct" way) ? i want to define this: "id" : 99, _info : { "name" : "somename", "href" : "someUrl" } Are any of the following two accurate?: 1) { "type": "object", "name":…
Gustavo
  • 685
  • 3
  • 7
  • 17
10
votes
1 answer

Generate JSON Schema for ASP.Net Web API

I'm looking to generate JSON Schema for a WebAPI, including documentation from the XML comments. Its primarily so that I can then import that into our API docs (using apiary.io) I've managed to get a workaround solution by adding swagger (and…
steve
  • 778
  • 1
  • 8
  • 18
10
votes
2 answers

How to make anyOf a set of mutually exclusive properties except one

I have a legacy API I'm trying to define in a JSON Schema and the object has a weird structure where there are a set of 4 properties, any one of them is required, and 3 of them are mutually exclusive. The are a more than 30 shared optional…
JaredMcAteer
  • 21,688
  • 5
  • 49
  • 65
9
votes
1 answer

Json Schema Example for patternProperties

can anyone give me an example of how to use the patternProperties item for json schema? "Example" : "type" : "object", "patternProperties" : { } What I want to do in the json file is allow any subitem of "Example"…
Stephan
  • 1,639
  • 3
  • 15
  • 26
9
votes
1 answer

Explanation of $dynamicRef $dynamicAnchor in Json Schema (as opposed to $ref and $anchor)

Can somebody explain the purpose of the $dynamicRef keyword in JSON Schema For an actual use, see the JSON Schema meta schema itself. It makes use of $dynamicAnchor and $dynamicRef. Core schema looks like this { "$schema":…
Andreas H.
  • 5,557
  • 23
  • 32