RDF / XML format for JSON
1 answer
You can use rdflib to parse many variations of RDF (including RDF / XML), or perhaps the simpler rdfparser if that suits your needs. You can then use the Python standard library module json
(or equivalently a third party simplejson
if you are using a version of Python older than 2.6) to serialize the inline memory structure generated with the parser to JSON. Unfortunately, I am not familiar with any package that implements both steps.
In the example on the rdfparser site, the overall work would only be ...:
import rdfxml
import json
class Sink(object):
def __init__(self): self.result = []
def triple(self, s, p, o): self.result.append((s, p, o))
def rdfToPython(s, base=None):
sink = Sink()
return rdfxml.parseRDF(s, base=None, sink=sink).result
s_rdf = someRDFstringhere()
pyth = rdfToPython(s_rdf)
s_jsn = json.dumps(pyth)
+8
a source to share