jsonschema

JSON Schema regarding use of $ref

天大地大妈咪最大 提交于 2019-11-30 04:24:40
I understand that $ref takes a URI to a json schema to use but where does $ref : "#" point to? Does it just mean use the current schema for this block level? Or does it mean to use the root level schema defined in the root level id? Thanks EDIT: So if I have: "items": { "anyOf": [ { "$ref": "#" }, { "$ref": "#/definitions/schemaArray" } ], "default": {} } Because it lacks an id field it will attempt to validate the instance items with the root schema first and then if that fails try to validate it with the schemaArray schema defined in the definitions schema, right? So if I change it to:

Use JSON.NET to generate JSON schema with extra attributes

依然范特西╮ 提交于 2019-11-30 03:47:57
I am using JSON.NET to generate JSON Schema from c# object class. But I was unable to add any other json schema attributes e.g. maxLength, pattern(regex to validate email), etc Below is my working code, I can only generate json schema with required attribute. It would be great if anyone can post some code example about how to add those extra attribute for json schema. Thanks, my code example public class Customer { [JsonProperty(Required = Required.Always)] public int CustomerID { get; set; } [JsonProperty(Required = Required.Always)] public string FirstName { get; set; } [JsonProperty

JSON schema : “allof” with “additionalProperties”

爱⌒轻易说出口 提交于 2019-11-30 02:38:51
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" }, "city": { "type": "string" }, "state": { "type": "string" } }, "required": ["street_address", "city", "state"] } }, "type": "object", "properties": { "billing_address": { "$ref": "#/definitions/address" }, "shipping_address": { "allOf": [ { "$ref": "#/definitions/address" }, { "properties": { "type": { "enum": [ "residential", "business" ] } }, "required": ["type"] } ] } } }

Flask: Decorator to verify JSON and JSON Schema

自作多情 提交于 2019-11-29 21:52:56
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 implemented in the following fashion: @app.route('/activate', methods=['POST']) def activate(): request_id = request.__hash__() # Assert that the payload is a valid JSON try: input = request.json except BadRequest, e: msg = "payload must be a valid json" return jsonify({"error": msg}), 400 # JSON Schema Validation try: validate(request.json, app.config[

json schema validation in java [closed]

吃可爱长大的小学妹 提交于 2019-11-29 18:51:59
I want to validate the json file using schema. How to do that. { "Book_information: [{ "BookName": "English", "ConfigFile": "English.json", "dependsOn": "Tamil", "maxPurchase": "1", "BookInformation": { "name": "English", "id": "English-1" } }, { "BookName": "Tamil", "ConfigFile": "Tamil.json", "maxPurchase": "3", "BookInformation": { "name": "Tamil", "id": "Tamil-1" } }] } If you're looking for an online tool then you can try jsonschemalint-online-validator If you need to validate it using Java code then validate-json-against-schema-in-java should help. It provides a step by step approach,

JSON Schema property dependent on value of previous property

一世执手 提交于 2019-11-29 16:32:12
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 specific answer. If question A does not have that answer, then the value to question B must be null. E.g. A: Do you like cars? Yes/No B: What is your favourite car? Question B can only be answered if the answer to question A is "Yes", otherwise it must be left null. After some research I have found this Stack Overflow thread, which describes the enum and if

How to change all keys to lowercase when parsing JSON to a JToken

末鹿安然 提交于 2019-11-29 14:00:18
I have a string of JSON and the keys have uppercase and lowercase characters: {"employees":[ {"FIrstName":"John", "LASTname":"Doe"}, {"FIRSTNAME":"Anna", "LaSTNaME":"Smith"}, {"firstName":"Peter", "lastName":"Jones"} ]} I want convert it to a JToken object and have all the keys in the JToken be lowercase. So internally in the JToken it should be as follows: {"employees":[ {"firstname":"John", "lastname":"Doe"}, {"firstname":"Anna", "lastname":"Smith"}, {"firstname":"Peter", "lastname":"Jones"} ]} Previously I was using JToken json = JToken.Parse(jsonString); to convert, but I can't find out

oneOf in Swagger schema does not work

时光毁灭记忆、已成空白 提交于 2019-11-29 13:21:42
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, and cardNumber where NewPaymentMethod will have no id , but all other details, e.g. cardNumber , cardholderName , cardholderAddress etc. Evan Torkos oneOf is supported in OpenAPI version 3 ( openapi: 3.0.0 ), but not in Swagger version 2 ( swagger: '2.0' ). PaymentMethod: oneOf: - $ref: '#/components/schemas/NewPaymentMethod' - $ref: '#/components/schemas

JSON Schema for tree structure

穿精又带淫゛_ 提交于 2019-11-29 11:37:51
I have to build tree like structure of Json data.Each node has an id (an integer, required), a label (a string, optional), and an array of child nodes (optional). Can you help me how to write JSON schema for this Json data. I need to set Id as required in child node as well. { "Id": 1, "Label": "A", "Child": [ { "Id": 2, "Label": "B", "Child": [ { "Id": 5, "Label": "E" }, { "Id": 6, "Label": "E" }, { "Id": 7, "Label": "E" } ] }, { "Id": 3, "Label": "C" }, { "Id": 4, "Label": "D", "Child": [ { "Id": 8, "Label": "H" }, { "Id": 9, "Label": "I" } ] } ] } enter image description here A schema for

Make sure item property in array is unique in Json Schema?

那年仲夏 提交于 2019-11-29 11:25:26
问题 Given the following JSON schema, is it possible to indicate that the "name" property shall be unique (i.e. there should NOT be two items with the same "name" in the "elements" array. { "root": { "type": "object", "properties": { "elements": { "type": "array", "minItems": 1, "items": { "type": "object", "properties": { "name": { "type": "string", "title": "Element Name", "minLength": 3, }, "url": { "type": "string", "title": "Some URL" } } } } } } } I tried to use the uniqueItems keyword but