json-gold
json-gold copied to clipboard
Schema Validation
It doesn't appear like there is a way to validate that a piece of conforms to a schema.
I would expect it to behave similarly to this tool and check that the provided schema(s) match the fields used: https://search.google.com/structured-data/testing-tool
Not sure how much work this would be to implement but I'm happy to lend a hand.
@ethernetdan This sounds like a very good idea! Few observations:
- JSON-LD context doesn't provide enough information about what may or may not be used/included into specific field. You will need to use a vocabulary (like http://schema.org/docs/schema_org_rdfa.html - apologies, I can't find the proper RDF representation right now) which may or may not be available for a specific context. I.e. it can't tell that the expected type of aggregateRating field is AggregateRating:
"aggregateRating": {
"@type": "AggregateRating",
"ratingValue": "4.5",
"reviewCount": "276",
"bestRating": "5",
"worstRating": "1"
}
This also may be an alreadt solved problem (for RDF). If that's the case, building a validator could be easy: use this library to transform JSON-LD into RDF quads and apply RDF based validation!
- I would be cautious about making any alterations into the core of JSON-API operations provided by this library (if required for adding the validation logic), because it closely follows the standard and reference implementations.
Feel free to expand, I'm open to suggestions!
@ethernetdan For schema validation, using json-schema. gojsonschema is a library for doing this in Go. You can use it to validate that a JSON-LD record is valid as well as the schemas themselves are valid.