你可以使用JSON-LD處理器(重新)創建你的數據庫更好的JSON。規定JSON-LD文檔結構的一個很好的可能性是to define a frame。從規格
報價:
JSON-LD幀允許開發人員通過實例來查詢並強制特定的樹佈局的JSON-LD文件。
例子:
假設你的文件看起來像
{
"@context": {
"contributor": {
"@type": "@id",
"@id": "http://purl.org/dc/terms/contributor",
"@container": "@list"
},
"label": {
"@id": "http://www.w3.org/2004/02/skos/core#prefLabel"
}
},
"@graph": [
{
"@type": "MainResource",
"@id": "_:foo",
"contributor": [
{
"@id": "_:N6e57c55b35b74782ada714fdc6d66bf1"
},
{
"@id": "_:N810e115dfb3348579a7b826a7548095b"
}
]
},
{
"@id": "_:N6e57c55b35b74782ada714fdc6d66bf1",
"@type": "Person",
"label": "Isely, Duane, 1918-"
},
{
"@id": "_:N810e115dfb3348579a7b826a7548095b",
"@type": "Person",
"label": "Cronquist, Arthur"
}
]
}
像
{
"@context": {
"contributor": {
"@type": "@id",
"@id": "http://purl.org/dc/terms/contributor",
"@container": "@list"
},
"label": {
"@id": "http://www.w3.org/2004/02/skos/core#prefLabel"
}
},
"@type": "MainResource",
"@embed": "always"
}
把它添加JSON-LD框到你選擇的JSON-LD處理器和你會得到像
{
"@context": {
"contributor": {
"@type": "@id",
"@id": "http://purl.org/dc/terms/contributor",
"@container": "@list"
},
"label": {
"@id": "http://www.w3.org/2004/02/skos/core#prefLabel"
}
},
"@graph": [
{
"@id": "_:b0",
"@type": "http://json-ld.org/playground/MainResource",
"contributor": [
{
"@id": "_:b1",
"@type": "http://json-ld.org/playground/Person",
"label": "Isely, Duane, 1918-"
},
{
"@id": "_:b2",
"@type": "http://json-ld.org/playground/Person",
"label": "Cronquist, Arthur"
}
]
}
]
}
這裏是json-ld.org/playground
完整的例子不幸的是取景不equaly很好的支持。所以結果取決於您使用的JSON-LD處理器。
您可以通過從數據中刪除「@」符號來進一步闡述。只需添加以下到您的上下文:
"type" : "@type",
"id" :"@id"
此外,還可以對類型添加酥油對上下文的文檔
"MainResource": "http://json-ld.org/playground/MainResource"
見例如json-ld.org/playground
對於rdf4j看看完整的代碼Java示例這裏:How to convert RDF to pretty nested JSON using java rdf4j。