Export jena model to json file

2019-07-24 19:51发布

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?

标签: java json jena
2条回答
对你真心纯属浪费
2楼-- · 2019-07-24 20:19

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);
查看更多
SAY GOODBYE
3楼-- · 2019-07-24 20:41
  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
查看更多
登录 后发表回答