tree-to-sparqljson
v1.0.2
Published
A package that helps to convert GraphQL JSON tree results into SPARQL JSON Results.
Maintainers
Readme
Tree to SPARQL JSON
tree-to-sparqljson is a utility package that converts GraphQL JSON tree results into SPARQL JSON results.
Installation
npm install tree-to-sparqljsonUsage
import { Converter } from 'tree-to-sparqljson';
const converter = new Converter();
const graphqlTreeResult = {
"data": {
"Person": [
{
"id": "http://example.org/alice",
"givenName": [
"Alice"
]
},
{
"id": "http://example.org/john",
"givenName": [
"John"
]
},
{
"id": "http://example.org/bob",
"givenName": [
"Bob"
]
}
]
}
};
const sparqlJsonResult = converter.treeToSparqlJson(graphqlTreeResult);
console.log(JSON.stringify(sparqlJsonResult, null, 2));Output:
{
"head": {
"vars": [
"Person_id",
"Person_givenName"
]
},
"results": {
"bindings": [
{
"Person_id": {
"type": "uri",
"value": "http://example.org/alice"
},
"Person_givenName": {
"type": "literal",
"value": "Alice"
}
},
{
"Person_id": {
"type": "uri",
"value": "http://example.org/john"
},
"Person_givenName": {
"type": "literal",
"value": "John"
}
},
{
"Person_id": {
"type": "uri",
"value": "http://example.org/bob"
},
"Person_givenName": {
"type": "literal",
"value": "Bob"
}
}
]
}
}License
This package is licensed under the MIT License.
