Export jena model to json file

核能气质少年 提交于 2019-12-11 00:32:19

问题


Hey i'm trying to make a web service and i'm using Jena distibution. At the moment i have created my model and its printing out in RDF/XML format. I want to get my data to a JSON file saved in my hard disk. How can i do that?


回答1:


  1. org.openjena.riot.out.RDFJSONWriter writes Talis-style RDF/JSON (i.e not JSON-LD).
  2. Look for a JSON-LD writer (I think there are ones that read RDF and write JSON-LD)
  3. Use SPARQL JSON Results format



回答2:


Now the Jena RIOT readers/writers support also the RDF/JSON serialization; then you just need to do the following:

org.openjena.riot.RIOT.init(); //wires RIOT readers/writers into Jena
java.io.OutputStream os = null;
// Serialize over an outputStream
os = new java.io.ByteArrayOutputStream();
model.write(os, "RDF/JSON", relativeUriBase);


来源:https://stackoverflow.com/questions/12518115/export-jena-model-to-json-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!