jsonldGraph top-level property
Global convenience variable for working with JSON-LD format
This variable provides direct access to the JSON-LD codec for easy encoding and decoding of RDFGraph data in JSON-LD format. It uses the default configuration of JsonLdGraphCodec with standard namespace mappings and default encoder/decoder options.
Using this global instance is recommended for most common JSON-LD operations
where custom configuration is not needed if you work with RdfGraph and
without named graphs.
Dataset and Named Graph Handling
JSON-LD provides native support for RDF datasets through the @graph keyword.
If you work with RdfDataset and named graphs, you should use JsonLdDatasetCodec
or the convenient jsonld codec instead.
When trying to decode a JSON-LD document that contains a top-level @graph property,
this codec will throw an exception because it doesn't support named graphs.
Configuration
Parameters:
- Uses default
RdfNamespaceMappingsfor standard namespace prefixes - Uses default JsonLdGraphEncoderOptions for serialization
- Uses default JsonLdGraphDecoderOptions for parsing
Examples
Basic usage:
// Decode JSON-LD string into an RDF graph
final jsonLdString = '''
{
"@context": {
"name": "http://xmlns.com/foaf/0.1/name"
},
"@id": "http://example.org/person/1",
"name": "John Smith"
}
''';
final graph = jsonldGraph.decode(jsonLdString);
// Encode an RDF graph to JSON-LD string
final serialized = jsonldGraph.encode(graph);
For custom JSON-LD processing options, create a specific instance of JsonLdGraphCodec with the desired configuration.
Implementation
final jsonldGraph = JsonLdGraphCodec();