Object of objects - adding objects

27 views
Skip to first unread message

ris...@gmail.com

unread,
Mar 10, 2017, 4:20:42 AM3/10/17
to JSON Schema
Hello,

I'm complete noob in JSON schema and trying to create my first form based on JSON schema. Can you please help me with this?

User can add new items specified by "items", when I specify array of objects


{
    "type": "object",
    "properties": {
        "array": {
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "string": {
                        "type": "string"
                    }
                }
            }
        }
    }
}

 
Result:

{
  "array": []
}







(Button "+item")

 
 
But what if I need object of objects? How to make it possible for user to add new objects, but only in format that I specify?

{
    "type": "object",
    "properties": {
        "object": {
            "type": "object",
            "properties": {
                "subobject": {
                    "type": "object",
                    "properties": {
                        "string": {
                            "type": "string"
                        }
                    }
                }
            }
        }
    }
}


Result:

{
  "object": {
    "subobject": {
      "string": ""
    }
  }
}
But user here can't add new objects with same format as "subobject".
 


(No possibility to add another "subobject").



Thank you very much for any help.

Henry Andrews

unread,
Mar 10, 2017, 12:49:21 PM3/10/17
to json-...@googlegroups.com
You want to add multiple subobjects under different key names but the same schema?  If so, instead of declaring one named property "subobject" under the "properties" keyword, just define your schema under the "additionalProperties" keyword.  That will allow any property of any name to be added with that schema.

thanks,
-henry



From: "ris...@gmail.com" <ris...@gmail.com>
To: JSON Schema <json-...@googlegroups.com>
Sent: Sunday, February 26, 2017 5:08 AM
Subject: [json-schema] Object of objects - adding objects

--
You received this message because you are subscribed to the Google Groups "JSON Schema" group.
To unsubscribe from this group and stop receiving emails from it, send an email to json-schema...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Reply all
Reply to author
Forward
0 new messages