You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Steve Vestal <st...@adventiumlabs.com> on 2021/08/08 14:41:16 UTC

Reading JSON-LD

I am reading a file using the following:

myModel.read(myInputStream, "JSON-LD");

I get an exception:

org.apache.jena.riot.RiotException: [line: 1, col: 1 ] Content is not 
allowed in prolog.
     at 
org.apache.jena.riot.system.ErrorHandlerFactory$ErrorHandlerStd.fatal(ErrorHandlerFactory.java:153)
     at 
org.apache.jena.riot.lang.ReaderRIOTRDFXML$ErrorHandlerBridge.fatalError(ReaderRIOTRDFXML.java:313)
     ...

The "ReaderRIOTRDFXML" makes me wonder if Jena is trying to input my 
data in RDF/XML rather than JSON-LD format.  I am still on Jena 3.17.  
Do I need a later version to read JSON-LD?



Re: Reading JSON-LD

Posted by aj...@apache.org.
The instructions for how to convert a given JSON-LD document from JSON into
RDF triples are found in a special section of JSON called the "context".
That context can be either included directly in the file or imported from
an external location, as you have discovered. It's convenient to do the
latter when you are going to reuse the same context for many documents and
you don't want to repeat it in each one.

Adam

On Sun, Aug 8, 2021, 1:27 PM Steve Vestal <st...@adventiumlabs.com>
wrote:

> Thanks, progress is made.  I am new to JSON-LD.  I get the following
> error.  Why does it need to load something using one of the IRIs found
> in the *.jsonld file?  Is this like an import that I can turn off?
>
> org.apache.jena.riot.RiotException: loading remote context failed:
> https://192.168.222.120:8111/osmc/schemas/resource
>
> On 8/8/2021 11:13 AM, Andy Seaborne wrote:
> > RDFDataMgr.read(model, myInputStream, Lang.JSONLD);
>
>

Re: Reading JSON-LD

Posted by Steve Vestal <st...@adventiumlabs.com>.
Thanks, progress is made.  I am new to JSON-LD.  I get the following 
error.  Why does it need to load something using one of the IRIs found 
in the *.jsonld file?  Is this like an import that I can turn off?

org.apache.jena.riot.RiotException: loading remote context failed: 
https://192.168.222.120:8111/osmc/schemas/resource

On 8/8/2021 11:13 AM, Andy Seaborne wrote:
> RDFDataMgr.read(model, myInputStream, Lang.JSONLD);


Re: Reading JSON-LD

Posted by Andy Seaborne <an...@apache.org>.

On 08/08/2021 15:41, Steve Vestal wrote:
> I am reading a file using the following:
> 
> myModel.read(myInputStream, "JSON-LD");
Wrong API call. The two arg version takes the base URI, not the language.

Model.read(InputStream, baseURI)


Try:

myModel.read(myInputStream, null, "JSON-LD");

or (better type checking):

RDFDataMgr.read(model, myInputStream, Lang.JSONLD);

or (buildler style arguments - this is what RDFDataMgr is built on):

RDFParser.source(myInputStream).lang(Lang.JSONLD).parse(model);

     Andy
> 
> I get an exception:
> 
> org.apache.jena.riot.RiotException: [line: 1, col: 1 ] Content is not 
> allowed in prolog.
>      at 
> org.apache.jena.riot.system.ErrorHandlerFactory$ErrorHandlerStd.fatal(ErrorHandlerFactory.java:153) 
> 
>      at 
> org.apache.jena.riot.lang.ReaderRIOTRDFXML$ErrorHandlerBridge.fatalError(ReaderRIOTRDFXML.java:313) 
> 
>      ...
> 
> The "ReaderRIOTRDFXML" makes me wonder if Jena is trying to input my 
> data in RDF/XML rather than JSON-LD format.

Correct.

>  I am still on Jena 3.17. Do 
> I need a later version to read JSON-LD?

No.

     Andy