jsonschema

How do I validate incoming JSON data inside a REST service?

喜你入骨 提交于 2019-11-27 04:15:05
A rest service needs to validate all incoming json data against a json schema. The json schemas are public accessible and can be retrieved via http requests. I'm using the jackson-framwork for marshaling and unmarshaling between java and json. So far I couldn't find any possibility to validate the data against the schema by using jackson. I also tried the JsonTools framework which obviously comes up with such a validation functionality. But unfortunately it wasn't possible for me to get the validation to work. Why JsonTool schema validation isn't working? How can I do such a validation? I

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

夙愿已清 提交于 2019-11-27 03:22:54
问题 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": { "type": "string" }, "bar": { "type": "string" } }, "if": { "properties": { "foo": { "enum": [ "bar" ] } } }, "then": { "required": [ "bar" ] } } If the "foo" property equals "bar", Then the "bar" property is required. This works as expected. However, if the "foo" property

JSON Schema - Recursive Schema Definition

橙三吉。 提交于 2019-11-27 03:11:40
问题 I have a JSON Schema { 'description': 'TPNode', 'type': 'object', 'id': 'tp_node', 'properties': { 'selector': { 'type': 'string', 'required': true }, 'attributes': { 'type': 'array', 'items': { 'name': 'string', 'value': 'string' } }, 'children': { 'type': 'array', 'items': { 'type': 'object', '$ref': '#' } }, 'events': { 'type': 'array', 'items': { 'type': 'object', 'properties': { 'type': { 'type': 'string' }, 'handler': { 'type': 'object' }, 'dependencies': { 'type': 'array', 'items': {

Json Schema example for oneOf objects

时光毁灭记忆、已成空白 提交于 2019-11-27 03:03:33
问题 I am trying to figure out how oneOf works by building a schema which validates two different object types. For example a person (firstname, lastname, sport) and vehicles (type, cost). Here are some sample objects: {"firstName":"John", "lastName":"Doe", "sport": "football"} {"vehicle":"car", "price":20000} The question is what have I done wrongly and how can I fix it. Here is the schema: { "description": "schema validating people and vehicles", "$schema": "http://json-schema.org/draft-04

Generate Json schema from XML schema (XSD) [closed]

放肆的年华 提交于 2019-11-27 03:03:19
Does anybody know how to generate a JSON schema from a existing XML schema (XSD file)? Are there any tools available for this? Disclaimer : I am the author of Jsonix , a powerful open-source XML<->JSON JavaScript mapping library. Today I've released the new version of the Jsonix Schema Compiler , with the new JSON Schema generation feature. Let's take the Purchase Order schema for example. Here's a fragment: <xsd:element name="purchaseOrder" type="PurchaseOrderType"/> <xsd:complexType name="PurchaseOrderType"> <xsd:sequence> <xsd:element name="shipTo" type="USAddress"/> <xsd:element name=

JSON Schema - specify field is required based on value of another field

血红的双手。 提交于 2019-11-27 01:14:19
问题 Wondering if this is possible with schema draft 03. I've gotten dependencies working elsewhere, I think there is possibly just some creative use of them required in order to use them for specifying the required property of some field. My current best attempt (which doesn't work) should give you some idea of what I'm after. I want a value required by default, and optional when another field has a particular value. { "description" : "An address...", "type" : "object", "properties" : { "postcode

Schema object without a type attribute in Swagger 2.0

天大地大妈咪最大 提交于 2019-11-26 23:39:02
问题 Does a Schema object in Swagger/OpenAPI 2.0 have to have the type attribute or not? On the one hand, according to the JSON Schema Draft 4 spec, not specifying the type attribute is OK and means that the instance can be of any type (an object, an array or a primitive). On the other hand, I've seen a lot of Swagger schemas which contain Schema objects without the type attribute, but with the properties attribute, which makes it clear that the schema author wants the instance to be a proper

How to use definitions in JSON schema (draft-04)

左心房为你撑大大i 提交于 2019-11-26 22:09:02
The rest service response I am working with is similar to following example, I have only included 3 fields here but there are many more: { "results": [ { "type": "Person", "name": "Mr Bean", "dateOfBirth": "14 Dec 1981" }, { "type": "Company", "name": "Pi", "tradingName": "Pi Engineering Limited" } ] } I want to write a JSON schema file for above (draft-04) which will explicitly specify that: if type == Person then list of required properties is ["type", "name", "dateOfBirth", etc] OR if type == "Company" then list of required properties is ["type", "name", "tradingName", etc] However am

Tool to generate JSON schema from JSON data [closed]

ぃ、小莉子 提交于 2019-11-26 19:19:20
We have this json schema draft . I would like to get a sample of my JSON data and generate a skeleton for the JSON schema, that I can rework manually, adding things like description, required, etc, which can not be infered from the specific examples. For example, from my input example.json : { "foo": "lorem", "bar": "ipsum" } I would run my json_schema_generator tool and would get: { "foo": { "type" : "string", "required" : true, "description" : "unknown" }, "bar": { "type" : "string", "required" : true, "description" : "unknown" } } This example has been coded manually, so it has maybe errors

Generate C# classes from JSON Schema [closed]

独自空忆成欢 提交于 2019-11-26 17:36:27
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed last year . I'm creating a C# WCF Web Service that return a lot of data in a JSON format. The client is an iPad application that is currently being developped by another team, So I'm working on specifications, without example data. Currently the JSON string is created by the .net framework, my Web Service is returning a C#