How to convert RDF to pretty nested JSON using java rdf4j

Use framing import java.io.ByteArrayInputStream; import java.io.InputStream; import java.io.StringWriter; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; import org.eclipse.rdf4j.model.Statement; import org.eclipse.rdf4j.rio.RDFFormat; import org.eclipse.rdf4j.rio.RDFHandlerException; import org.eclipse.rdf4j.rio.RDFParser; import org.eclipse.rdf4j.rio.RDFWriter; import org.eclipse.rdf4j.rio.Rio; import org.eclipse.rdf4j.rio.helpers.StatementCollector; import org.junit.Test; import com.github.jsonldjava.core.JsonLdOptions; import com.github.jsonldjava.core.JsonLdProcessor; import com.github.jsonldjava.utils.JsonUtils; import com.google.common.base.Charsets; public class HowToConvertRdfToJson { @Test public void convertRdfToPrettyJson(){ try(InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(“book.ttl”)){ System.out.println(getPrettyJsonLdString(in,RDFFormat.TURTLE)); }catch(Exception e){ … Read more

tech