Re: [json-schema] Re: Ways of defining array of custom JSON-type

758 views
Skip to first unread message

Andrew Todd

unread,
Nov 17, 2014, 2:18:52 PM11/17/14
to json-...@googlegroups.com
Yes. In fact that's a simpler use case than using a definitions block. Did you try it out and face some difficulty?

On Mon, Nov 17, 2014 at 1:49 PM, Amit Ruparel <amitru...@gmail.com> wrote:
Bump!


On Friday, 14 November 2014 16:06:23 UTC-8, Amit Ruparel wrote:
Hi all,

I'm aware the if you want to define an Array of custom JSON objects, you can do it this way:

{
    "title": "Product",
    "type": "object",
    "properties": {
        "id": {
            "description": "The unique identifier for a product",
            "type": "integer"
        },
        "tags": {
            "type": "array",
            "items": {
                "$ref": "#/definitions/tagObj"
            }
        }
    }
    "definitions" : {
        "tagObj" : {
            "properties" : {
                "tagInfo" : { "type" : "string" },
                "tagInfo2" : { "type" : "string" }
            }
        }
    }
}

But instead of having an explicit definition and a reference to it, can you directly define the custom JSON object inline this way?:

{
    "title": "Product",
    "type": "object",
    "properties": {
        "id": {
            "description": "The unique identifier for a product",
            "type": "integer"
        },
        "tags": {
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "tagInfo" : { "type" : "string" },
                    "tagInfo2" : { "type" : "string" }
               }
            }
        }
    }
}

Thanks!

--
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.

Andrew Todd

unread,
Nov 18, 2014, 10:17:35 AM11/18/14
to json-...@googlegroups.com
Generally speaking, if it works as expected in fge's validator, it's legal syntax. https://json-schema-validator.herokuapp.com/

On Mon, Nov 17, 2014 at 2:21 PM, Amit Ruparel <amitru...@gmail.com> wrote:
No. I think I didn't find any such examples, so just wanted to double check.
Thanks!

--
You received this message because you are subscribed to a topic in the Google Groups "JSON Schema" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/json-schema/bm_rfLd4U1I/unsubscribe.
To unsubscribe from this group and all its topics, send an email to json-schema...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--

Amit Ruparel

Graduate Student - MS, Computer Science

C O L U M B I A U N I V E R S I T Y

Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
Message has been deleted
0 new messages