PHPackages                             accredifysg/php-json-ld - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. accredifysg/php-json-ld

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

accredifysg/php-json-ld
=======================

A PHP implementation of the JSON-LD 1.1 specification.

v2.0.0(1mo ago)0165↓38.1%1[5 PRs](https://github.com/Accredifysg/PHP-JSON-LD/pulls)MITPHPPHP ^8.2CI passing

Since May 20Pushed 2w agoCompare

[ Source](https://github.com/Accredifysg/PHP-JSON-LD)[ Packagist](https://packagist.org/packages/accredifysg/php-json-ld)[ Docs](https://github.com/accredifysg/php-json-ld)[ RSS](/packages/accredifysg-php-json-ld/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (2)Dependencies (18)Versions (80)Used By (0)

PHP-JSON-LD
===========

[](#php-json-ld)

A PHP implementation of the [JSON-LD 1.1](https://www.w3.org/TR/json-ld11/) specification.

> **Status: stable.** The public API is stable and the project follows [Semantic Versioning](https://semver.org/) — breaking changes bump the major version. The package delivers spec-compliant JSON-LD 1.1 **Expansion**, **Compaction**, **Serialize to RDF** (`toRdf`), **Flattening**, **RDF-to-JSON-LD** (`fromRdf`), and **Framing**, validated against the official W3C JSON-LD 1.1 test suites — see the [compliance matrix](#compliance)for per-algorithm conformance and the [CHANGELOG](CHANGELOG.md) for the enumerated residual blockers.

Goals
-----

[](#goals)

- Faithful implementation of the JSON-LD 1.1 algorithms defined in the [JSON-LD 1.1 Processing Algorithms and API](https://www.w3.org/TR/json-ld11-api/).
- Pluggable document loader so consumers (e.g. verifiable-credential libraries) can serve known `@context` URLs from local resources.
- No mandatory HTTP client dependency — bring your own (Guzzle is suggested, not required).
- Tested against the [official W3C JSON-LD test suite](https://github.com/w3c/json-ld-api).

Scope (delivered)
-----------------

[](#scope-delivered)

- Custom `DocumentLoader` interface
- Expansion (§5.5) — **381/385 of the W3C expand suite** (the remaining 4 are environment/spec-accommodation blockers)
- Compaction (§5.6) — **246/246 of the W3C compact suite (100%)**: container-maps (incl. property-valued `@index`, `@type`-map node refs), keyword recursion, `@nest`, nested `@list`, `@graph` maps, `@reverse` (incl. per-value term selection and containers), full inverse-context term scoring (list/direction-aware, `@json` literals), property-/type-scoped contexts with scoped `@base`/`@vocab`, IRI relativisation, expand-first normalisation, the `compactArrays` option, §5.7 prefix rules and error conditions
- Serialize JSON-LD to RDF (§7 / `toRdf`) — **463/467 of the W3C toRdf suite** (the remaining 4 are environment/spec-accommodation blockers); N-Quads output incl. `rdfDirection`, `produceGeneralizedRdf`, and JCS `@json` canonicalization
- Flattening (§4.6 / `flatten`) — **58/58 of the W3C flatten suite (100%)**; folds named graphs into `@graph`, with optional compaction when a context is supplied
- RDF to JSON-LD (§4.9 / `fromRdf`) — **49/53 of the W3C fromRdf suite**; a built-in dependency-free N-Quads parser, `useNativeTypes` / `useRdfType`, `rdf:first`/`rest`/`nil` list reconstruction, and `@json` literals (remaining: list-of-lists conversion + two non-normative compound-literal cases)
- Framing (`frame`) — **89/92 of the W3C json-ld-framing suite**; merged/default-graph framing, `@type`/`@id`/value/node-pattern matching, wildcard `{}` vs `match none` `[]`, `@embed` (`@once`/`@never`/`@always`), `@explicit`, `@default`/`@omitDefault`/`@requireAll`, `@graph`/`@included`/`@reverse` framing (incl. `@container:@graph`), blank-node pruning, and `omitGraph` (remaining 3 are compaction safe-mode strictness, `@language` case-normalization, and the legacy `@embed: @last`)

> Suite numbers from v0.42.0 use the spec-accurate `toEqual` comparison (object-key order insignificant, array order significant); earlier numbers used a looser comparison and are not directly comparable — see the CHANGELOG.

A frame's `{}` wildcard cannot be represented in PHP's associative-array model (it decodes the same as `[]`), so the framing API treats an empty frame value as `match none` and accepts the documented `Expansion::FRAME_WILDCARD` sentinel for a wildcard.

Installation
------------

[](#installation)

```
composer require accredifysg/php-json-ld:^1.0
```

Requires PHP 8.2+. You also need a PSR-18 HTTP client + PSR-17 request factory if you use the bundled `HttpDocumentLoader` (e.g. `guzzlehttp/guzzle`and `guzzlehttp/psr7`), or you can implement `DocumentLoader` yourself to serve `@context` URLs from wherever you like.

Usage
-----

[](#usage)

```
use Accredify\JsonLd\JsonLdProcessor;
use Accredify\JsonLd\Loaders\CachingDocumentLoader;
use Accredify\JsonLd\Loaders\HttpDocumentLoader;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\HttpFactory;

$loader = new CachingDocumentLoader(
    new HttpDocumentLoader(new Client, new HttpFactory),
);

$processor = new JsonLdProcessor($loader);
$expanded = $processor->expand($yourDocument)->toArray();
```

If you want to serve known contexts from local files (recommended for verifiable credentials), implement `Accredify\JsonLd\Contracts\DocumentLoader`yourself. See [`tests/Algorithms/Characterization/Support/BundledContextLoader.php`](tests/Algorithms/Characterization/Support/BundledContextLoader.php)for an example.

Compliance
----------

[](#compliance)

The package is tested against the [official W3C JSON-LD 1.1 test suite](https://github.com/w3c/json-ld-api), pulled in as a git submodule at `tests/w3c/`. See [tests/W3c/README.md](tests/W3c/README.md) for harness layout and how to run it.

```
# Run only the project's unit tests (the default)
composer test

# Run the W3C conformance suite
composer test:w3c
```

### Conformance matrix

[](#conformance-matrix)

AlgorithmSpecW3C suitePassingConformanceExpansion§5.53853814 documented blockersCompaction§5.6246246**100%**Serialize to RDF (`toRdf`)§74674634 documented blockersFlattening§4.65858**100%**RDF to JSON-LD (`fromRdf`)§4.953494 documented blockersFramingframing §492893 documented blockers**Totals: 1286 / 1301 passing** across the six manifests; Compaction and Flattening are fully conformant. The 15 residual non-conformances (4 in expand, 4 in toRdf, 4 in fromRdf, 3 in framing) are mostly negative-test / non-normative / environment limits:

- `#tc032` / `#tc033` — *unused* embedded contexts aren't validated (negative tests)
- `#ter56` — redefining the `@context` keyword isn't rejected (negative test)
- `#t0122` (expand only) — keyword-shaped (`@`) IRIs are dropped rather than kept as `{@id: null}` (non-normative)
- `#tjs10` (toRdf only) — JSON-literal structural canonicalization differs
- `#t0008` / `#tli03` (fromRdf) — list-of-lists conversion (the 1.0 shape / nested ordering); single-level lists are fully supported
- `#tdi11` / `#tdi12` (fromRdf, non-normative) — compound-literal direction folding
- `#t0010` (framing) — compaction safe-mode rejects `dcterms:creator` as an IRI confused with the `dcterms` prefix (the reference processor errors here too)
- `#t0045` (framing) — `@language` case-normalization (expansion preserves case, which the consensus-critical `toRdf` bytes depend on)
- `#t0059` (framing) — the legacy `@embed: @last` mode (the `@once` default is implemented)

These are carried as an explicit expected-failure allowlist ([`tests/W3c/KnownBlockers.php`](tests/W3c/KnownBlockers.php)) so the conformance suite stays green and **gates CI** — any new regression, or a listed blocker that starts passing, fails the build. See the [CHANGELOG](CHANGELOG.md) and [tests/W3c/README.md](tests/W3c/README.md) for the full release-over-release history.

> Counts use the spec-accurate `toEqual` comparison (object-key order insignificant, array order significant) introduced in v0.42.0; earlier figures used a looser comparison and are not directly comparable.

### Characterization fixtures

[](#characterization-fixtures)

`tests/Algorithms/Characterization/` holds JSON snapshots of the expander's output, generated from running the original `accredifysg/verifiable-credentials-php` JsonLdProcessor over a set of sample documents. They are NOT a spec-conformance reference — they pin the package's behaviour so that any change to expansion output lands as a reviewable diff.

When a PR changes expansion in a way that updates these fixtures, the update should be reviewed for correctness and paired with any matching change in downstream consumers (e.g. VC's signed-credential test fixtures).

License
-------

[](#license)

[MIT](LICENSE) © Accredify

###  Health Score

48

—

FairBetter than 94% of packages

Maintenance95

Actively maintained with recent releases

Popularity16

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 89.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

73

Last Release

35d ago

Major Versions

v0.69.0 → v1.0.02026-06-11

v1.0.1 → v2.0.02026-06-19

PHP version history (2 changes)v0.1.0PHP ^8.1

v1.0.1PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/baf5a0854c8d40389bb8d2177472f8d5d2fa063ec1a57064df36a9b819fac868?d=identicon)[skydudie](/maintainers/skydudie)

---

Top Contributors

[![skydudie](https://avatars.githubusercontent.com/u/28289296?v=4)](https://github.com/skydudie "skydudie (93 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (9 commits)")[![rezaramadhan](https://avatars.githubusercontent.com/u/15650702?v=4)](https://github.com/rezaramadhan "rezaramadhan (2 commits)")

---

Tags

JSON-LDjsonldW3CRDFSemantic WebLinked Data

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/accredifysg-php-json-ld/health.svg)

```
[![Health](https://phpackages.com/badges/accredifysg-php-json-ld/health.svg)](https://phpackages.com/packages/accredifysg-php-json-ld)
```

###  Alternatives

[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k16](/packages/tempest-framework)[flow-php/flow

PHP ETL - Extract Transform Load - Data processing framework

85036.3k](/packages/flow-php-flow)[cakephp/cakephp

The CakePHP framework

8.8k19.5M1.8k](/packages/cakephp-cakephp)[telnyx/telnyx-php

Official Telnyx PHP SDK — APIs for Voice, SMS, MMS, WhatsApp, Fax, SIP Trunking, Wireless IoT, Call Control, and more. Build global communications on Telnyx's private carrier-grade network.

36789.4k2](/packages/telnyx-telnyx-php)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)[anthropic-ai/sdk

Anthropic PHP SDK

163583.3k20](/packages/anthropic-ai-sdk)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
