Reputation: 4511
I have a JSON object:
{
"name" : "car",
"color" : "blue"
}
And a JSON Schema which is used to validate it (not specified here).
XML allows you to include a reference to an extern XML Schema Definition for validation in the XML document itself via "xsi:schemaLocation" (the namespace prefix might be different).
Is there an equivalent way to include a reference to a JSON Schema in a JSON object?
Upvotes: 0
Views: 604
Reputation: 12863
The link from data to a schema describing it is generally considered "metadata", so usually isn't in the data itself.
If you're working over HTTP, you can:
rel="describedby"
to link to the schema.The second option is preferable.
If you're loading from a file, or something else, then it's not defined. Within your own application, you are perfectly free to define something like "$schema"
to reference schemas. Although other tools wouldn't pick up on this automatically, it would be obvious to any other developers what you were doing.
Upvotes: 2