How to handle JSON-schema name conflict with JSON name

286 views
Skip to first unread message

Toby

unread,
May 1, 2018, 11:56:56 AM5/1/18
to JSON Schema
Hi folks

Apologies in advance if this is already documented, I have taken a look around json-schema.org and didn't find the info.

I am designing a JSON-schema schema for YAML. The YAML as it currently stands uses a key named "type".
Obviously this conflicts with the "type" in the schema:

"items": {
   
"description": "A sequence offoo object",
   
"type": "object",
   
"name": {
       
"description": "A foo object",
       
"type": "string"
   
},
   
"type": {
       
"description": "The type of the foo, 'compressed', 'scan', 'peg', etc",
       
"type": "string"
   
}
}

In this example the YAML 'type' key that has a string value conflicts with the JSON-schema 'type' that specifies that the sequence items are objects.
Is there a best-practice way of solving this?

Many thanks, T

Ben Hutton (@Relequestual)

unread,
May 1, 2018, 12:00:50 PM5/1/18
to JSON Schema

Hi Toby,

 

 

You have to put the properties of your object in a properties key word.

The properties key word defines what properties of the object are to be validated (or stuff).


Take a look at the example at http://json-schema.org/examples.html

The value of "items" must be a JSON schema, which means the example schema could be the value of "items" in your schema.


Make sense?

(Feel free to join the slack if not)


Cheers

Ben

Toby

unread,
May 2, 2018, 4:34:25 AM5/2/18
to JSON Schema
Thanks Ben,

Despite having looked at the JSON for a full 20 minutes I didn't spot that I had missed the properties key. D'oh!

Cheers, T

Ben Hutton (@Relequestual)

unread,
May 2, 2018, 4:38:31 AM5/2/18
to JSON Schema
You're welcome. I've done that before!

Cheers
Ben
Reply all
Reply to author
Forward
0 new messages