I have created a Graph() in rdflib 6.2.0 and attempting to export it as JSON-LD. My expectation was that I would end up with a @context containing all the namespace prefixes and a @graph containing all the elements. I'm just simply using:
myGraph.serialize(destination = Path(outputpath), format = "json-ld")
But, I just end up with JSON-LD resembling this kind of structure:
[
{
"@id": "urn:uuid:dccc2ddb-7861-47fc-934c-d2a0901e368e",
"@type": "http://xmlns.com/foaf/0.1/Organization",
},
... (more resources in a flat list)
]
The docs (https://rdflib.readthedocs.io/en/stable/apidocs/rdflib.plugins.serializers.html#rdflib.plugins.serializers.jsonld.JsonLDSerializer) do not really clarify the matter at all, and it is very difficult to find any information on how to export a graph with already existing namespace bindings into a proper JSON-LD with @graph and @context parts.
There exists a Context class in https://rdflib.readthedocs.io/en/stable/apidocs/rdflib.plugins.shared.jsonld.html?highlight=shared.jsonld.context#rdflib.plugins.shared.jsonld.context.Context but without any documentation in the sources, it is very difficult to understand how it should be used. What does the method get_graph() do? Apparently I need to pass a Context instance to the json-ld serializer?
What am I doing wrong?