Вы можете использовать jsonld-java с кадрированием, чтобы преобразовать ваш JSON-LD результат в красивый вложенный JSON .Результат преобразования будет семантически эквивалентным.
Попробуйте
private static String getPrettyJsonLdString(String rdfGraphAsJson) {
try {
//@formatter:off
return JsonUtils
.toPrettyString(
getFramedJson(
createJsonObject(
rdfGraphAsJson)));
//@formatter:on
} catch (Exception e) {
throw new RuntimeException(e);
}
}
private static Map<String, Object> getFramedJson(Object json) {
try {
return JsonLdProcessor.frame(json, getFrame(), new JsonLdOptions());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
private static Map<String, Object> getFrame() {
Map<String, Object> frame = new HashMap<>();
/*
Use @type to define 'root' object to embed into
*/
frame.put("@type" , "dcat:Distribution");
Map<String,Object>context=new HashMap<>();
context.put("dct", "http://purl.org/dc/terms/");
context.put("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
context.put("dcat", "http://www.w3.org/ns/dcat#");
context.put("example", "http://example.com/vocabulary/");
frame.put("@context", context);
return frame;
}
private static Object createJsonObject(String ld) {
try (InputStream inputStream =
new ByteArrayInputStream(ld.getBytes(Charsets.UTF_8))) {
Object jsonObject = JsonUtils.fromInputStream(inputStream);
return jsonObject;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Это даст
{
"@context" : {
"dct" : "http://purl.org/dc/terms/",
"rdf" : "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"dcat" : "http://www.w3.org/ns/dcat#",
"example" : "http://example.com/vocabulary/"
},
"@graph" : [ {
"@id" : "http://example.com/datasets/1",
"@type" : "dcat:Distribution",
"example:props" : {
"@id" : "_:b0",
"example:prop1" : "hello",
"example:prop2" : "1"
}
} ]
}