ml/json-ld
Fully conforming JSON-LD processor for PHP. Implements the official JSON-LD API (expand, compact, frame, flatten, toRdf), passes the W3C test suite, supports advanced framing features, and includes N-Quads serialization/parsing.
Begin by installing via Composer: composer require ml/json-ld. After autoloading, the fastest path to value is using the static JsonLD API—start with JsonLD::expand() to normalize any JSON-LD input (e.g., expanding Schema.org microdata for SEO validation), or JsonLD::compact() with a reusable context (e.g., @context for schema.org) to standardize output. Use the online playground to experiment with transformations before coding. A common first task: embed structured data in Blade templates by compacting internal data into schema.org-compliant JSON-LD using JsonLD::toString(JsonLD::compact($data, $context), true).
Leverage the procedural JsonLD facade for core pipeline operations in controllers or services:
<script type="application/ld+json"> blocks by compacting product/order/event data using JsonLD::compact($document, $schemaContext).JsonLD::frame() to extract specific subsets (e.g., author-only views) from complex JSON-LD APIs, or JsonLD::flatten() to normalize graph structures before storage.JsonLD::toRdf() and NQuads for interoperability with graph databases (e.g., Blazegraph, RDF4J) via Laravel queued jobs.JsonLD::getDocument() → $doc->getGraph()->getNode($id) → $node->addPropertyValue() → $graph->toJsonLd(). Note: Reserve this for low-volume, graph-intensive tasks due to experimental status.JsonLD::expand() always returns an array of graphs—even with one document—so use reset($expanded) to get the top-level graph.['@context' => include 'context.jsonld'] or inject via Laravel config._:b0 are regenerated per operation—never rely on them for state persistence; assign stable @ids early.memory_get_usage() and consider chunking or async processing in Laravel queues.JsonLD::toString($value, true) (pretty-print enabled).ext-json and ml/iri (auto-required) are installed; missing ext-json causes silent failures—add a health check in AppServiceProvider.How can I help you explore Laravel packages today?