JsonLdGraphCodec class final

RDF Format implementation for the JSON-LD serialization format.

JSON-LD (JavaScript Object Notation for Linked Data) is a method of encoding Linked Data using JSON. It was designed to be easy for humans to read and write, while providing a way to represent RDF data in the widely-used JSON format.

JSON-LD Key Concepts

JSON-LD extends JSON with several special keywords (always prefixed with @):

  • @context: Maps terms to IRIs and defines data types for values

    • Enables shorthand property names in place of full IRIs
    • Specifies how to interpret values (strings, numbers, dates, etc.)
  • @id: Uniquely identifies a node (equivalent to the subject in RDF)

  • @type: Indicates the resource's type (equivalent to rdf:type)

  • @graph: Contains a set of nodes in a named graph

Example JSON-LD Document

{
  "@context": {
    "name": "http://xmlns.com/foaf/0.1/name",
    "knows": {
      "@id": "http://xmlns.com/foaf/0.1/knows",
      "@type": "@id"
    },
    "born": {
      "@id": "http://example.org/born",
      "@type": "http://www.w3.org/2001/XMLSchema#date"
    }
  },
  "@id": "http://example.org/john",
  "name": "John Smith",
  "born": "1980-03-15",
  "knows": [
    {
      "@id": "http://example.org/jane",
      "name": "Jane Doe"
    }
  ]
}

Benefits of JSON-LD

  • Uses standard JSON syntax, familiar to web developers
  • Compatible with existing JSON APIs and tools
  • Designed to integrate easily with the web (HTTP, REST)
  • Can express complex RDF data models in a human-readable form
  • Supports framing, compaction, and expansion operations

File Extension and MIME Types

JSON-LD files typically use the .jsonld file extension. The primary MIME type is application/ld+json.

Inheritance

Constructors

JsonLdGraphCodec({RdfNamespaceMappings? namespaceMappings, JsonLdEncoderOptions encoderOptions = const JsonLdEncoderOptions(), JsonLdDecoderOptions decoderOptions = const JsonLdDecoderOptions()})
Creates a new JSON-LD codec with optional configuration
const

Properties

decoder RdfGraphDecoder
Creates a decoder instance for this codec
no setteroverride
encoder RdfGraphEncoder
Creates an encoder instance for this codec
no setteroverride
hashCode int
The hash code for this object.
no setterinherited
inverted Codec<String, RdfGraph>
Inverts this.
no setterinherited
primaryMimeType String
The primary MIME type for this codec
no setteroverride
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
supportedMimeTypes Set<String>
All MIME types supported by this codec
no setteroverride

Methods

canParse(String content) bool
Tests if the provided content is likely in this codec's format
override
decode(String input, {String? documentUrl, RdfGraphDecoderOptions? options}) RdfGraph
Decodes a string containing RDF data into an RDF graph
inherited
encode(RdfGraph input, {String? baseUri, RdfGraphEncoderOptions? options}) String
Encodes an RDF graph to a string representation in this codec
inherited
fuse<R>(Codec<String, R> other) Codec<RdfGraph, R>
Fuses this with other.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited
withOptions({RdfGraphEncoderOptions? encoder, RdfGraphDecoderOptions? decoder}) JsonLdGraphCodec
Creates a new codec instance with the specified options
override

Operators

operator ==(Object other) bool
The equality operator.
inherited