Last active
September 27, 2023 10:00
-
-
Save jaw111/3955e6fb9aa48c7d627cec685a9d5cca to your computer and use it in GitHub Desktop.
Validate rdf:JSON typed literal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . | |
@prefix ex: <http://example.com/> . | |
# valid JSON literals | |
ex:bob ex:has '{"name": robert"}'^^rdf:JSON . | |
ex:bob ex:has '{"name": ["robert", "bob"]}'^^rdf:JSON . | |
# invalid JSON literals | |
ex:bob ex:has '{"name": "robert"}'^^rdf:JSON . | |
ex:bob ex:has '{"name": ["robert", "bob",]}'^^rdf:JSON . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PREFIX js: <http://jena.apache.org/ARQ/jsFunction#> | |
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> | |
SELECT ?o (js:isJsonLiteralValid(?o) AS ?isValid) | |
WHERE { | |
?s ?p ?o . | |
FILTER (datatype(?o) = rdf:JSON) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// validate json | |
function isJsonLiteralValid(jsonLiteral) { | |
try { | |
JSON.parse(jsonLiteral); | |
return true; | |
} catch(e) { | |
return false; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
export JVM_ARGS=-Djena:scripting=true | |
arq --set arq:js-library=myjs.js --query jsontest.rq --data json-literals.ttl |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment