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
33
votes
2 answers

jsonschema multiple values for string property

I have a json schema which describes a fairly complex API querying syntax. A few of the properties are pattern matched but also need to accept other values (i.e. other explicit strings) other than just the pattern. I can't seem to find anywhere in…
Jeff U.
  • 616
  • 1
  • 6
  • 12
33
votes
3 answers

Generate Avro Schema from certain Java Object

Apache Avro provides a compact, fast, binary data format, rich data structure for serialization. However, it requires user to define a schema (in JSON) for object which need to be serialized. In some case, this can not be possible (e.g: the class…
Richard Le
  • 639
  • 2
  • 9
  • 20
33
votes
2 answers

How to create JSON Schema for Name/Value structure?

My problem is that i am serializing the content of map to JSON. In the output (JSON), i have object that follow key/name syntax rule. The key is created from map key, and the name from the value. Model Example: class Storage { …
32
votes
4 answers

JSON Schema compared with XML Schema and their future

I was looking for JSON schema standards and their corresponding php implementations. Expecting some open source out there and I was surprised, to find only one php implementation. I was about using this technology (JSON) and the schema lib to…
Alain
  • 1,450
  • 3
  • 20
  • 37
31
votes
1 answer

How to represent sum/union types in in json schema

I am trying to document an existing use of JSON using json-schema. The system permits the following two possabilities for one of the object attributes. Either { "tracking_number" : 123 } Or { "tracking_number" : [ 123, 124, 125 ] } How…
Q the Platypus
  • 825
  • 1
  • 7
  • 13
31
votes
1 answer

How do I validate a JSON Schema schema, in Python?

I am programmatically generating a JSON-Schema schema. I wish to ensure that the schema is valid. Is there a schema I can validate my schema against? Please note my use of schema twice in that sentence and the title. I don't want to validate data…
GDorn
  • 8,511
  • 6
  • 38
  • 37
30
votes
3 answers

Can I set exact value in a JSON Schema?

I use JSON Schema to validate app objects against some schema for testing. I see that I can set minimum and maximum values for a property: "responseCode": { "type": "integer", "minimum": 100, "maximum": 500 } But I…
Sergei Basharov
  • 51,276
  • 73
  • 200
  • 335
28
votes
5 answers

django postgresql json field schema validation

I have a django model with a JSONField (django.contrib.postgres.fields.JSONField) Is there any way that I can validate model data against a json schema file? (pre-save) Something like my_field = JSONField(schema_file=my_schema_file)
Mr T.
  • 4,278
  • 9
  • 44
  • 61
28
votes
3 answers

Flask: Decorator to verify JSON and JSON Schema

I have a flask application with calls expecting JSON payload. Before each call is processed, I have a 2-step error checking process: Assert that the payload is a valid JSON Assert that the JSON payload complies with a specific schema Which is…
Adam Matan
  • 128,757
  • 147
  • 397
  • 562
28
votes
2 answers

Why is this json schema invalid? using "any" type

{ "$schema": "http://json-schema.org/draft-04/schema#", "title": "my json api", "description": "my json api", "type": "object", "properties": { "my_api_response": { "type": "object", "properties":…
tadasajon
  • 14,276
  • 29
  • 92
  • 144
26
votes
6 answers

How to set up local file references in python-jsonschema document?

I have a set of jsonschema compliant documents. Some documents contain references to other documents (via the $ref attribute). I do not wish to host these documents such that they are accessible at an HTTP URI. As such, all references are relative.…
Chris W.
  • 37,583
  • 36
  • 99
  • 136
26
votes
3 answers

Should a RESTful API have a schema?

I was told recently that a proper RESTful API should define a schema for the resources representations it accepts and returns. For example XSD for XML and JSON Schema for JSON. However in all the books and articles on REST I went through this has…
Sebastian K
  • 6,235
  • 1
  • 43
  • 67
26
votes
1 answer

How to write a JSON schema for array of objects?

My JSON string would be formatted as: { "count":3, "data":[ { "a":{"ax":1} }, { "b":{"bx":2} }, { "c":{"cx":4} } ] } The data array contains many a and…
Green Su
  • 2,318
  • 2
  • 22
  • 16
25
votes
3 answers

How do I use the `If` `then` `else` condition in json schema?

A relatively new addition to JSON Schema (draft-07) adds the if, then and else keywords. I cannot work out how to use these new key words correctly. Here is my JSON Schema so far: { "type": "object", "properties": { "foo": { …
Mohammad Irfan
  • 253
  • 1
  • 3
  • 7
25
votes
4 answers

How to define JSON Schema for Map?

I have a json : { "itemTypes": {"food":22,"electrical":2}, "itemCounts":{"NA":211} } Here the itemTypes and itemCounts will be common but not the values inside them (food, NA, electrical) which will be keep changing but the will be in the format :…
Newbie
  • 691
  • 4
  • 16
  • 28