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

Convert JSON to JSON Schema draft 4 compatible with Swagger 2.0

I've been given some JSON files generated by a REST API with plenty of properties. I've created a Swagger 2.0 definition for this API and need to give it the corresponding schema for the response. The main problem: this JSON file has loads of…
Cwellan
  • 305
  • 1
  • 3
  • 12
20
votes
5 answers

JSON schema validation with PHP

Is there any PHP library that validates a JSON object against a JSON Schema?
Omer
  • 582
  • 3
  • 14
  • 24
19
votes
3 answers

OpenAPI query string parameter with list of objects

I am trying to document with OpenAPI a query string which look like filtered[0][id]=code&filtered[0][value]=12345 and contains a list of object with properties id and value. My yaml documentation looks like the following parameters: - name:…
marcosh
  • 8,780
  • 5
  • 44
  • 74
19
votes
2 answers

JSON Schema v4 "required" in nested object

I tried searching, but I'm not quite sure how to put this in words! The point of confusion is how "required" works in JSON schema v4 when there are nested key values with the same name. For example, this schema: { "Root": { "type":…
Kevin
  • 753
  • 2
  • 8
  • 18
19
votes
2 answers

Is JSON validation a best practice?

Is it a best practice to validate JSON? With both a JSON schema proposal and a JavaScript implementation of a JSON Schema validator, this practice would seem relatively frictionless to implement. So, is it a no-brainer that should be part of any…
user290
19
votes
4 answers

Decimal precision in JSON Schema

I want to have my JSON Schema validate that no more than two decimal places are sent to my REST api. From what I can see in the latest JSON Schema RFC (v4) doesn't allow this. V1 had a maxDecimals validator. Does anyone know why that was taken…
Jay Pete
  • 4,123
  • 4
  • 35
  • 51
19
votes
2 answers

JSON schema draft4 VS JSON schema draft3

What are the features present in the schema draft 4 that are not in the JSON schema draft 3 produced by IETF ?
user2430996
  • 341
  • 1
  • 4
  • 12
19
votes
1 answer

JSON schema validation with arbitrary keys

I am using validictory for validating the attached JSON data and schema. Working so far. However the data dictionary can have arbitrary string keys (others than 'bp' but). The key 'bp' in the schema here is hard-coded...it can be a string from a…
user2665694
18
votes
5 answers

VScode - Unable to load schema for package.json

So I was working on a project and today I saw an error about VScode being unable to resolve package.json schema: CSS contributions to package.json Problems loading reference 'vscode://schemas/settings/configurationDefaults': Unable to load schema…
VivaceNonTroppo
  • 456
  • 1
  • 3
  • 13
18
votes
3 answers

How do you use the JSON Schema 'default' attribute in Json.NET?

If I have a JSON Schema that specifies a default value for a property, like { "type" : "object", "properties" : { "foo" : { "type" : "string" }, "bar" : { "type" : "string", "default" : "some text" } } } ...and a JSON…
John Reynolds
  • 4,927
  • 4
  • 34
  • 42
18
votes
2 answers

JSON Schema: How to check that an array contains at least one object with a property with a given value?

How can I check in the following json that at least one element in the array names has a property nickName with the value Ginny? { "names": [ { "firstName": "Hermione", "lastName": "Granger" }, { "firstName": "Harry", …
fpenim
  • 491
  • 1
  • 4
  • 14
18
votes
3 answers

JSON Schema to GraphQL schema converters

Are there any adapters which are converting JSON Schema schemas (e.g from Swagger) to GraphQL schemas? There is even an official article about wrapping around REST http://graphql.org/blog/rest-api-graphql-wrapper/, but usually REST already described…
Rax Wunter
  • 2,677
  • 3
  • 25
  • 32
18
votes
3 answers

oneOf in Swagger schema does not work

I want to define PaymentMethod as below. Is oneOf supported in swagger.yaml? PaymentMethod: oneOf: - $ref: '#/definitions/NewPaymentMethod' - $ref: '#/definitions/ExistPaymentMethod' The ExistPaymentMethod will have just id,…
fastcodejava
  • 39,895
  • 28
  • 133
  • 186
18
votes
2 answers

What is the difference between "anyof" and "oneof" in z schema?

Its looking like both works fine with my input validation code. Then what is the exact difference? Schema with oneof [{ "id": "MyAction", "oneOf": [{ "$ref": "A1" }, { "$ref": "A2" }] }, { "id": "A1", "properties": { …
Somnath
  • 3,247
  • 4
  • 28
  • 42
18
votes
2 answers

json schema property description and "$ref" usage

I am writting a json schema to validate my json outputs produced by an exe.The schema being little bit complexe, I have defined some "definitions" that are referenced in properties ("$ref": "#/definitions/...). And using definitions here is all the…
Azias
  • 547
  • 1
  • 4
  • 12