jsonschema - Need help :Json Schema Design -
i designing the json scheme. , facing issues while designing schema.
here problem.
i have array of group objects. , want array should contain unique group objects. want make them unique based on object id ( ex group.id)
the groups array not unique if (groups[0].id == groups[1].id) , want make unique based on group id, below json structure.
"groups": { "type": "array", "items": {"$ref": "#/group"}, "uniqueitems":true }, "group": { "type": "object", "properties": { "id": {"type": "integer"}, "type": { "type": "string", "enum": [ "a", "b" ] }, "command": { "type": "string", "enum": [ "add", "modify" ] } } },
well, there no magic bullet here. remind json-schema intended defining structure of json data (not values).
one option not consider groups node "array" instead "object", , use additionalproperties express additional properties should contain "type" , "command" properties.
then use name of each property in groups id, unique.
the problem approach not restrict id numeric (it might not acceptable in context). use patternproperties match "type,command" schema numeric "id's".
Comments
Post a Comment