given this RDF:
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
@prefix ex: <http://example.com/>.
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
ex:bob ex:has '{"name": robert"}'^^rdf:JSON .
ex:bob ex:at "204453"^^xsd:dateTime .
an RDF engine (such as Apache Jena) can validate some of the typed literals (e.g. xsd:dateTime):
$ ~/Downloads/apache-jena-4.7.0/bin/riot --validate file.ttl
11:48:47 WARN riot :: [line: 6, col: 14] Lexical form '204453' not valid for datatype XSD dateTime
will any RDF engines validate the rdf:JSON
typed literal?
notice the json isn’t well-formed.
2
Answers
I like John Walker's solution but we also discovered that if you attempt to serialize that RDF (with the malformed json literal) as jsonld using Apache Jena it will validate the json literals:
You can use JavaScript SPARQL Functions in ARQ to implement a simple custom function that will tell you if a literal is parsable as JSON.
This Gist demonstrates how that can be done: https://gist.github.com/jaw111/3955e6fb9aa48c7d627cec685a9d5cca