Convert RDF to JSON for ultimate use in Javascript framework

943 views
Skip to first unread message

cabusc...@gmail.com

unread,
Mar 22, 2017, 12:17:07 PM3/22/17
to rdflib-dev
Hello
I am working on a project to convert RDF data to JSON, with the goal of using it in a web framework.

I have tried some XML to JS conversion tools, but they never quite work on RDF XML, but do on regular XML documents.

So, for example, I have this:

<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description xmlns:ns1="dc:" rdf:about="http://localhost:8080/cgi-bin/koha/opac-detail.pl?biblionumber=3140">
<ns1:creator rdf:resource="https://fr.wikipedia.org/wiki/Katherine_Paterson"/>
</rdf:Description>
</rdf:RDF>
</xml>

Which seems to not play nice with, for example, the JQuery parser.

I am wondering..would this library help me with my goal?

Thanks so much

Michael Cabus

Marc-Antoine Parent

unread,
Mar 22, 2017, 12:21:42 PM3/22/17
to rdfli...@googlegroups.com
Yes, rdflib can parse RDF (in many formats) and emit various JSON formats.
I strongly recommend looking at json-ld, which is a very flexible format that allows you to express your RDF resources in a variety of json structures that are ideally consumable by javascript. Rdflib has a good jsonld module.
Regards,
Marc-Antoine Parent
> --
> http://github.com/RDFLib
> ---
> You received this message because you are subscribed to the Google Groups "rdflib-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rdflib-dev+...@googlegroups.com.
> To post to this group, send email to rdfli...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rdflib-dev/1d45e649-e2f8-47b9-ab96-fabfd0dac967%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

knab...@gmail.com

unread,
May 20, 2017, 2:35:43 PM5/20/17
to rdflib-dev
I am unable to convert my rdf xml into json I have looked a lot over internet but I am unable to do it can u please tell in detail how to convert a large rdf/xml to json objects

Jon Crump

unread,
May 21, 2017, 2:53:10 PM5/21/17
to rdfli...@googlegroups.com
if you install this: https://github.com/RDFLib/rdflib-jsonld

then you can do this (python 2.7):

>>> from rdflib import Graph
>>> g = Graph()
>>> xml = """<?xml version="1.0"?>
... 
... <rdf:RDF
... 
... <rdf:Description rdf:about="https://www.w3schools.com">
...   <si:title>W3Schools</si:title>
...   <si:author>Jan Egil Refsnes</si:author>
... </rdf:Description>
... 
... </rdf:RDF>"""
>>> g.parse(data = xml)
<Graph identifier=N5188733317044266a20c3957e8365a76 (<class 'rdflib.graph.Graph'>)>
>>> print g.serialize(format = 'json-ld')
[
  {
      {
        "@value": "Jan Egil Refsnes"
      }
    ],
      {
        "@value": "W3Schools"
      }
    ]
  }
]
>>>

–– Si vis pacem, bellum adflicta. ––


> > To unsubscribe from this group and stop receiving emails from it, send an email to rdflib-dev+unsubscribe@googlegroups.com.

> > To post to this group, send email to rdfli...@googlegroups.com.
> > To view this discussion on the web visit https://groups.google.com/d/msgid/rdflib-dev/1d45e649-e2f8-47b9-ab96-fabfd0dac967%40googlegroups.com.
> > For more options, visit https://groups.google.com/d/optout.
--
http://github.com/RDFLib
---
You received this message because you are subscribed to the Google Groups "rdflib-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rdflib-dev+unsubscribe@googlegroups.com.

To post to this group, send email to rdfli...@googlegroups.com.

Shaozhong Shi

unread,
Sep 5, 2017, 6:37:00 AM9/5/17
to rdflib-dev
Is there a neat Hello World Python example?

Regards,

David
Reply all
Reply to author
Forward
0 new messages