If I have a JSON document like:
{
"142.250.193.14": {},
"2404:6800:4002:819::200e": {},
"google.com": {},
}
i.e., it has ipv4/ipv6 addresses and hostnames as keys and the values are irrelevant to the question. How can I define a JSON schema that uses the built-in formats to check for these, I tried using patternProperties but a regex for all of these is quite complex.
2
Answers
Don’t have a full answer for you, but there are a bunch of IPV6 regex examples that come close, like this one from regexr. Those could be a starting point for the JSON.
That’s the
propertyNames
keyword, which lets you use a schema to define the structure of the property name, when it’s more complicated than a pattern would allow for.https://json-schema.org/understanding-json-schema/reference/object.html#property-names
You need to make sure that your evaluator is validating formats, as that’s specified to be disabled by default.