Reputation: 1071
We are developing a REACT application that needs to get a list of the JSON schema standard built-in formats. According to json-schema.org reference page the built-in formats are as follows:
I'd rather if I didn't have to hardcode those values in our application, so how can we retrieve a list of those possible values programmatically?
[EDIT]
A clarification, we are developing a JSON schema that sets "$schema": "http://json-schema.org/schema"
. This is how the app would be able to identify that we are using the current JSON Schema specification. From there we are looking for a way to load possible values for "format"
so we can present it in the UI.
Upvotes: 0
Views: 212
Reputation: 8428
$schema
indicates the version of the specification that the schema that declares it is using.
Each version of the specification declares a (small) static set of available formats.
It's not unreasonable to hardcode these sets into a lookup by $schema
value. There are only 4 or 5 (if you include draft 4) values for this keyword, unless you're writing your own meta-schemas.
I've hardcoded them into my JSON Schema library, JsonSchema.Net.
If you're looking for an automated way to find these values, you're going to have to scan the specification documents themselves. They're not listed in the meta-schemas, which is what you get when you navigate to the URI (not a URL) find in $schema
. The meta-schema just requires that format
's value is a string.
The specification intentionally leaves this open-ended so that people can create their own custom formats.
Upvotes: 2