jsonld

package
v0.1.16 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 14, 2026 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Overview

Package jsonld implements a JSON-LD parser and serializer using piprate/json-gold.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(g *rdflibgo.Graph, r io.Reader, opts ...Option) error

Parse parses a JSON-LD document into the given graph. It uses piprate/json-gold to expand the document to N-Quads, then parses those into the graph. Options: WithBase, WithDocumentLoader, WithSkipInvalidIRIs, WithUnboundedLines.

func Serialize

func Serialize(g *rdflibgo.Graph, w io.Writer, opts ...Option) error

Serialize serializes a Graph to JSON-LD format. It converts the graph to N-Quads (preserving named graph context), then uses piprate/json-gold to produce JSON-LD output. Options: WithBase, WithForm/WithExpanded, WithDocumentLoader.

Types

type Option

type Option func(*config)

Option configures JSON-LD parsing or serialization.

func WithBase

func WithBase(base string) Option

WithBase sets the base IRI for JSON-LD processing.

func WithDocumentLoader

func WithDocumentLoader(loader ld.DocumentLoader) Option

WithDocumentLoader sets a custom document loader for remote context resolution.

func WithExpanded

func WithExpanded() Option

WithExpanded is a convenience option to request expanded JSON-LD output.

func WithForm

func WithForm(form OutputForm) Option

WithForm sets the output form for JSON-LD serialization (compact or expanded).

func WithSkipInvalidIRIs added in v0.1.10

func WithSkipInvalidIRIs() Option

WithSkipInvalidIRIs makes parsing tolerant of syntactically invalid IRIs (e.g. a stray space, as in "schema: Dataset") that the JSON-LD expander emits into the intermediate N-Quads instead of dropping. The offending triple is silently skipped and parsing continues, rather than failing the whole document.

This matches Python rdflib/pySHACL, which drop such triples before validation. The default (option unset) is strict: an invalid IRI is a hard error. Note that the bundled JSON-LD processor already drops most malformed IRIs on its own; this option is a safety net for IRIs that slip through to the N-Quads layer.

func WithUnboundedLines added in v0.1.11

func WithUnboundedLines() Option

WithUnboundedLines parses intermediate N-Quads lines of arbitrary length, growing the read buffer as needed. This is useful when JSON-LD expansion produces very large literal values on a single N-Quads line.

type OutputForm

type OutputForm int

OutputForm specifies the JSON-LD output format.

const (
	// FormCompacted applies JSON-LD compaction using namespace bindings (default).
	FormCompacted OutputForm = iota
	// FormExpanded outputs expanded JSON-LD without compaction.
	FormExpanded
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL