Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

How to specify that a property of type object can appear only 1 time (i think this is default), N times, or any times? Or even not at all.

The question is, how to translate the standard UML composition cardinality information (min..max) to JSON Schema in case of properties of type 'object'?

"A" : {
   "type" : "object",
   "properties" : {
             "B" :  {
                     "type" : "object"

based on this schema, A may contain exactly one B, however I need to be able to specify: - if it may contain none - it may contain more (n) - it may contain any

Thanks: Endre

If you want to show the meta-definition info in JSon, a natural solution would be to add a "MultiplicityElement" and "AggregationKind" attributes (like in the UML metamodel):

"A": { "type": "object", "properties": [ "B": { "type": "object", "AggregationKind": "composite", "MultiplicityElement": { "lower": 0, "upper": "n"

You might want to use "class" instead of "object" in this case, since you actually define your class structure. Alternative values for AggregationKind are "shared" (for aggregation) or "none".

Note that I put "properties" in a [] brackets, to indicate that there can be further properties added.

UPDATE (after the 1st comment)

First of all - the JSon is perfectly valid. Take a lok at this site: http://jsonlint.com/ I don't have time to investigate the reason of the fault on the one proposed by you, I suspect it has to do with the schema.

And more important - be careful here, I think you are mixing meta-model with model-information. I suspected this during my original answer and now you practically confirmed it.

The question is do you intend to show description of a class model (meta-model level) or description of a object model (model level).

  • If this is a class model description: change type to "class" and describe each class only once
  • If this is an object model: add a tag "class" to indicate the base class, use "values" instead of the "properties", use "property" instead of "type" to indicate the corresponding properties, remove AggregationKind and MultiplicityElement.
  • Or clarify your intention :)

    I have tested this with the [JSON online validator] (json-schema-validator.herokuapp.com). It does not recognise neither AggregationKind nor MultiplicityElement. But the good news is that it accepts a single B, no B, or any number of Bs. Any idea how to constraint the number of Bs that can be contained in A ? – user3211860 Apr 19, 2014 at 19:19 That's json schema validator. JSON and JSON schema are not the same thing. Aleks seems to confuse them – themihai May 26, 2015 at 18:54

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.