I'm aware that conversion of RDF to JSON-LD has some limitations, but I wonder if there is a good way of making the conversion avoid use of blank nodes?
For example, given an RDF graph:
@prefix ex: <http://example.org/ontology#> .
<http://example.org/x123> ex:house [
a ex:House ;
ex:houseNumber "1a" ;
ex:doorColour "blue"
] ;
ex:house [
a ex:House ;
ex:houseNumber "1b" ;
ex:doorColour "green"
] .
Is it possible, using (Java) JSON-LD to enforce conversion to an array-based representation of the bnodes:
{
"id": "http://example.org/x123",
"house": [{
"type": "House",
"houseNumber": "1a",
"doorColour": "blue"
}, {
"type": "House",
"houseNumber": "1b",
"doorColour": "green"
}],
"@context": {
"ex": "http://example.org/ontology#",
"house": "ex:house",
"houseNumber": "ex:houseNumber",
"doorColour": "ex:doorColour",
"House": "ex:House",
"id": "@id",
"type": "@type"
}
}
Rather than something like:
{
"@graph": [
{
"@id": "_:b0",
"@type": "http://example.org/ontology#House",
"http://example.org/ontology#doorColour": "blue",
"http://example.org/ontology#houseNumber": "1a"
},
{
"@id": "_:b1",
"@type": "http://example.org/ontology#House",
"http://example.org/ontology#doorColour": "green",
"http://example.org/ontology#houseNumber": "1b"
},
{
"@id": "http://example.org/x123",
"http://example.org/ontology#house": [
{
"@id": "_:b0"
},
{
"@id": "_:b1"
}
]
}
]
}
At the moment, I'm iterating over the statements in the graph and manually producing the JSON, but is it at all possible to do this using libraries like java-jsonld or some other JSON-LD technique?
You can use framing to achieve that. Have a look at the library example in the JSON-LD playground. Unfortunately it is not standardized yet so various implementations may not produce exactly the same output and/or super different features
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With