Hi All, Based on the above discussion, I need to finalize the JSON schema format generated for below use cases.
1. When the root element is an array Input: [ "777925", "732321" ] Json Schema : { "$schema" : "http://json-schema.org/draft-04/schema#", "id" : "http://wso2jsonschema.org", "title" : "root", "type" : "array", *"items" : [ {* * "id" : "http://wso2jsonschema.org/0 <http://wso2jsonschema.org/0>",* * "type" : "string"* * } ]* } 2. When the root element is an array of objects where object has elements Input: [ { "id": 0, "species": "Capra hircus", "name": "Goat" }, { "id": 1, "species": "Panthera pardus", "name": "Leopard" }, { "id": 2, "species": "Equus zebra", "name": "Zebra" } ] Json Schema : { "$schema" : "http://json-schema.org/draft-04/schema#", "id" : "http://wso2jsonschema.org", "title" : "root", "type" : "array", "items" : [ { "id" : "http://wso2jsonschema.org/0", "type" : "object", "properties" : { * "species" : {* * "id" : "http://wso2jsonschema.org/0/species <http://wso2jsonschema.org/0/species>",* * "type" : "string"* * },* * "name" : {* * "id" : "http://wso2jsonschema.org/0/name <http://wso2jsonschema.org/0/name>",* * "type" : "string"* * },* * "id" : {* * "id" : "http://wso2jsonschema.org/0/id <http://wso2jsonschema.org/0/id>",* * "type" : "number"* * }* * }* } ] } *Since this object does not wrap with a root element, is the visual representation correct for this type of a payload?* 3. When root element is an array of objects and the object is wrapped with another object Input: [ { "test":{ "id": 0, "species": "Capra hircus", "name": "Goat" } }, { "test":{ "id": 0, "species": "Capra hircus", "name": "Goat" } } ] Json Schema: { "$schema" : "http://json-schema.org/draft-04/schema#", "id" : "http://wso2jsonschema.org", "title" : "root", "type" : "array", "items" : [ { "id" : "http://wso2jsonschema.org/0", "type" : "object", "properties" : { * "test" : {* * "id" : "http://wso2jsonschema.org/0/test <http://wso2jsonschema.org/0/test>",* * "type" : "object",* * "properties" : {* * "species" : {* * "id" : "http://wso2jsonschema.org/0/test/species <http://wso2jsonschema.org/0/test/species>",* * "type" : "string"* * },* * "name" : {* * "id" : "http://wso2jsonschema.org/0/test/name <http://wso2jsonschema.org/0/test/name>",* * "type" : "string"* * },* * "id" : {* * "id" : "http://wso2jsonschema.org/0/test/id <http://wso2jsonschema.org/0/test/id>",* * "type" : "number"* * }* * }* } } } ] } Apart from the above samples, can there be a sample where the root element is an array of different objects ? eg: [ { "test1":{ "id": 0, "species": "Capra hircus", "name": "Goat" } }, { "test2":{ "id": 0, "species": "Capra hircus", "name": "Goat" } } ] If that's the case, is the below json schema correct? { "$schema":"http://json-schema.org/draft-04/schema#", "id":"http://wso2jsonschema.org", "title":"root", "type":"array", "items":[ { "id":"http://wso2jsonschema.org/0", "type":"object", "properties":{ "test1":{ "id":"http://wso2jsonschema.org/0/test", "type":"object", "properties":{ "species":{ "id":"http://wso2jsonschema.org/0/test/species", "type":"string" }, "name":{ "id":"http://wso2jsonschema.org/0/test/name", "type":"string" }, "id":{ "id":"http://wso2jsonschema.org/0/test/id", "type":"number" } } }, "test2":{ "id":"http://wso2jsonschema.org/0/test", "type":"object", "properties":{ "species":{ "id":"http://wso2jsonschema.org/0/test/species", "type":"string" }, "name":{ "id":"http://wso2jsonschema.org/0/test/name", "type":"string" }, "id":{ "id":"http://wso2jsonschema.org/0/test/id", "type":"number" } } } } } ] } Appreciate your input on this Thanks, Sohani Sohani Weerasinghe Senior Software Engineer WSO2, Inc: http://wso2.com Mobile : +94 716439774 Blog :http://christinetechtips.blogspot.com/ Twitter : https://twitter.com/sohanichristine On Wed, May 25, 2016 at 2:51 PM, Sohani Weerasinghe <soh...@wso2.com> wrote: > > > Sohani Weerasinghe > Software Engineer > WSO2, Inc: http://wso2.com > > Mobile : +94 716439774 > Blog :http://christinetechtips.blogspot.com/ > Twitter : https://twitter.com/sohanichristine > > On Wed, May 25, 2016 at 2:48 PM, Nuwan Pallewela <nuw...@wso2.com> wrote: > >> Hi Sohani, >> >> On Wed, May 25, 2016 at 11:03 AM, Sohani Weerasinghe <soh...@wso2.com> >> wrote: >> >>> Hi All, >>> >>> Since there can be JSON payloads without a root element as shown below, >>> we are in a process of generating the JSON schema for such payloads. Please >>> find the implementation details >>> >>> eg 1: >>> >>> *Input*: >>> >>> [ >>> "777925", >>> "732321" >>> ] >>> >>> *JSON schema:* >>> >>> { >>> "$schema" : "http://json-schema.org/draft-04/schema#", >>> "id" : "http://wso2jsonschema.org", >>> "title" : "root", >>> "type" : "array", >>> "items" : { >>> "id" : "http://wso2jsonschema.org/0", >>> "type" : "string" >>> } >>> } >>> >>> >>> I think this primitive array should be able to map. >> Yes, This should be able to map and I'm in a process of implementing it >> > eg 2: >>> >>> *Input*: >>> >>> [ >>> { >>> "id": 0, >>> "species": "Capra hircus", >>> "name": "Goat" >>> }, >>> { >>> "id": 1, >>> "species": "Panthera pardus", >>> "name": "Leopard" >>> }, >>> { >>> "id": 2, >>> "species": "Equus zebra", >>> "name": "Zebra" >>> } >>> ] >>> >>> *JSON Schema:* >>> >>> { >>> "$schema" : "http://json-schema.org/draft-04/schema#", >>> "id" : "http://wso2jsonschema.org", >>> "title" : "root", >>> "type" : "array", >>> "items" : { >>> "id" : "http://wso2jsonschema.org/0", >>> "type" : "object", >>> "properties" : { >>> "species" : { >>> "id" : "http://wso2jsonschema.org/0/species", >>> "type" : "string" >>> }, >>> "name" : { >>> "id" : "http://wso2jsonschema.org/0/name", >>> "type" : "string" >>> }, >>> "id" : { >>> "id" : "http://wso2jsonschema.org/0/id", >>> "type" : "number" >>> } >>> } >>> } >>> } >>> >>> >>> Thanks, >>> Sohani >>> >>> Sohani Weerasinghe >>> Software Engineer >>> WSO2, Inc: http://wso2.com >>> >>> Mobile : +94 716439774 >>> Blog :http://christinetechtips.blogspot.com/ >>> Twitter : https://twitter.com/sohanichristine >>> >> >> >> >> -- >> ---------------------------------------------------------- >> >> *Nuwan Chamara Pallewela* >> >> >> *Software Engineer* >> >> *WSO2, Inc. *http://wso2.com >> *lean . enterprise . middleware* >> >> Email *nuw...@wso2.com <nuw...@wso2.com>* >> Mobile *+94719079739 <%2B94719079739>@* >> >> >> >
_______________________________________________ Dev mailing list Dev@wso2.org http://wso2.org/cgi-bin/mailman/listinfo/dev