Export jena model to json file

2019-07-24 20:17发布

问题:

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);


标签: java json jena