Here I want to convert the JSON file into RDF. Here is the JSON
{
"glossary": {
"title": "example glossary",
"GlossDiv": {
"title": "S",
"GlossList": {
"GlossEntry": {
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"GlossDef": {
"para": "A meta-markup language, used to create markup languages such as DocBook.",
"GlossSeeAlso": ["GML", "XML"]
},
"GlossSee": "markup"
}
}
}
}
}
I could not find a proper way to convert it into RDF.
There is no standard way to interpret JSON as RDF. There are several ways you can generate RDF from a JSON file though (in Java or otherwise). You could simply use a JSON parser implemented in Java, then extract the relevant parts and build an RDF graph using a Java library for RDF such as Apache Jena or RDF4J (formerly known as Sesame). However, there are other ways that could make the task much easier:
@context
to it. This works well for simple cases but is not sufficient to cover many relevant cases.Disclaimer: I contributed to SPARQL-Generate.
If your aim is to simply get valid RDF without making any decisions about structure, you could trivially add a @context object and turn the existing JSON into JSON-LD, e.g.
{
"@context": {"@vocab": "http://example.org/ontology#"},
"glossary": {
"title": "example glossary",
"GlossDiv": {
"title": "S",
"GlossList": {
"GlossEntry": {
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"GlossDef": {
"para": "A meta-markup language, used to create markup languages such as DocBook.",
"GlossSeeAlso": ["GML", "XML"]
},
"GlossSee": "markup"
}
}
}
}
}
This can then be interpreted as RDF using an appropriate RDF/JSON-LD library, the RDF structure would be:
@prefix ns0: <http://example.org/ontology#> .
[] ns0:glossary [
ns0:GlossDiv [
ns0:GlossList [ ns0:GlossEntry [
ns0:Abbrev "ISO 8879:1986" ;
ns0:Acronym "SGML" ;
ns0:GlossDef [
ns0:GlossSeeAlso "GML", "XML" ;
ns0:para "A meta-markup language, used to create markup languages such as DocBook."
] ;
ns0:GlossSee "markup" ;
ns0:GlossTerm "Standard Generalized Markup Language" ;
ns0:ID "SGML" ;
ns0:SortAs "SGML"
] ] ;
ns0:title "S"
] ;
ns0:title "example glossary"
] .
This is perhaps strange RDF, but it can be loaded and manipulated using RDF tools.
You can play with the example in the json-ld playground
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With