jsonschema

enforce empty JSON schema

跟風遠走 提交于 2019-12-23 09:25:01
问题 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", "additionalProperties": false, "properties": { } } 回答1: The answer yes this should enforce an empty schema - the validator I was using had a bug http://groups.google.co.uk/group/json-schema/browse_thread/thread/d0017b3985c8542b/106ce4afc1763eeb?hl=en&q=empty+schema

how write json schema to show a property based on another property value using json-editor?

折月煮酒 提交于 2019-12-23 03:03:29
问题 I'm using Json-editor for creating a page to edit a json schema. I would like to set a property to be visible only if another property is set as true , for instance: property has_pets will rule the visibility of a pets array. I was not able to find anything, only enforcing the validation field. How can I write a schema definition to does not show a property based on another property value? 来源: https://stackoverflow.com/questions/51884859/how-write-json-schema-to-show-a-property-based-on

Newtonsoft JSON Schema Ignore Validations For Deserialize

倖福魔咒の 提交于 2019-12-23 02:47:18
问题 I have following JSON & class, { "Id": 123, "FirstName": "fName", "LastName": "lName" } public class Student { public int Id { get; set; } [StringLength(4)] public string FirstName { get; set; } [StringLength(4)] public string LastName { get; set; } } I'm trying to deserialize above JSON to create an instance of student class. var body = //above json as string; Student model = null; JSchemaGenerator generator = new JSchemaGenerator(); JSchema schema = generator.Generate(typeof(Student));

How to reference external files with JSON.net?

ⅰ亾dé卋堺 提交于 2019-12-22 13:57:26
问题 Here is the error I am getting when JSON.net is trying to read my JSON schema ( return JsonSchema.Read(new JsonTextReader(reader)); ): 2014-07-15 15:33:42.7011 [Fatal] Newtonsoft.Json.JsonException: Could not resolve schema reference 'data-result.json'. at Newtonsoft.Json.Schema.JsonSchemaBuilder.ResolveReferences(JsonSchema schema) in c:\Development\Releases\Json\Work ing\Newtonsoft.Json\Src\Newtonsoft.Json\Schema\JsonSchemaBuilder.cs:line 139 at Newtonsoft.Json.Schema.JsonSchemaBuilder

JSON SCHEMA: Can we do an either/or (string/int) for type?

落爺英雄遲暮 提交于 2019-12-22 10:53:29
问题 I'm doing a schema to validate contact information. In the phone number validation, we have a country code. I am really hoping there's a way to allow the country code to either be a string or an integer . Users from different countries inform me that there are sometimes meaningful non-integer characters in the country code (such as a "+"). That being said, a string makes sense. On the other hand, if someone provides a country code as an int, say .. something like 33 (france), I feel it'd be a

JSON schema conditional dependency on value

我的未来我决定 提交于 2019-12-22 08:04:25
问题 I know there is a similar question here, but it didn't really address my issue. In short, I want one my fields to be dependent on the other field's value. But for some values, I don't want any field to be required. Here is an example: Schema { "definitions": {}, "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "properties": { "colour": { "type": "string", "enum": ["red", "black", "blue"] }, "blackQuote": { "type": "string", "maxLength": 11 }, "redQuote": { "type":

writing more complex json schemas that have dependencies upon other keys

有些话、适合烂在心里 提交于 2019-12-22 05:33:28
问题 I've been writing simple JSON schemas but I ran into an API input call that is a bit more complex. I have one restful end route that can take 3 very different types of JSON: localhost/foo can take: { "type" : "ice_cream", "cone" : "waffle" ...} or {"type" : "hot_dog", "bun" : "wheat" ...} If the "type" key contains "ice_cream", I only ever want to see the key "cone" and not the key "bun". Similiarly if "type" contains "hot_dog" I only want to see "bun" and not "cone". I know I can pattern

JSON Schema oneOf properies filled

自作多情 提交于 2019-12-22 03:16:47
问题 How to set JSON Schema rule to say that exactly one of the properties have to be set and is required? I tried various ways to solve it like: { "id":"#", "required":true, "additionalProperties":true, "type":"object", "properties":{ "surname":{ "id":"surname", "required":true, "type":"string" }, "oneOf":[ { "$ref":"#/definitions/station_id" }, { "$ref":"#/definitions/station" } ] }, "definitions":{ "station_id":{ "type":"integer" }, "station":{ "type":"string" } } } But it never worked. What I

JSON Schema oneOf properies filled

雨燕双飞 提交于 2019-12-22 03:16:33
问题 How to set JSON Schema rule to say that exactly one of the properties have to be set and is required? I tried various ways to solve it like: { "id":"#", "required":true, "additionalProperties":true, "type":"object", "properties":{ "surname":{ "id":"surname", "required":true, "type":"string" }, "oneOf":[ { "$ref":"#/definitions/station_id" }, { "$ref":"#/definitions/station" } ] }, "definitions":{ "station_id":{ "type":"integer" }, "station":{ "type":"string" } } } But it never worked. What I

JSON schema to enforce array contents

本小妞迷上赌 提交于 2019-12-21 07:05:29
问题 Hi all and thanks in advance. I am attempting to create a JSON schema to enforce an array to contain one A and B object and N C objects, where A and B are C objects and N is an integer inclusively between 0 and infinity. Therefor : [A, B] [A, B, C1] [A, B, C1, .., CN] Are all valid , though : [A] [A, C1] [A, C1, .., CN] Are not valid . To make clear, A and B must be present. C objects are optional, though you may have as many as you would like. C object schemas : { "$schema": "http://json