sweetrdf/json-ld
Composer 安装命令:
composer require sweetrdf/json-ld
包简介
JSON-LD Processor for PHP
README 文档
README
Note
This is a fork of the Original JsonLD library written by Markus Lanthaler. I maintain it in my spare time to keep it alive and usable on the latest PHP versions. Code is more or less maintained but not developed any further. If you wanna participate, feel free to open a pull request!
JsonLD is a fully conforming JSON-LD processor written in PHP. It is extensively tested and passes the official JSON-LD test suite.
There's an online playground where you can evaluate the processor's basic functionality.
Additionally to the features defined by the JSON-LD API specification, JsonLD supports framing (including value matching, deep-filtering, aggressive re-embedding, and named graphs) and an experimental object-oriented interface for JSON-LD documents.
Installation
JsonLD requires PHP 8.1 or later.
The easiest way to install JsonLD is by requiring it with Composer.
composer require sweetrdf/json-ld
Of course, you can also download JsonLD as ZIP archive from Github.
Usage
The library supports the official JSON-LD API as well as a object-oriented interface for JSON-LD documents (not fully implemented yet, see issue #15 for details).
All classes are extensively documented. Please have a look at the source code.
// Official JSON-LD API $expanded = JsonLD::expand('document.jsonld'); $compacted = JsonLD::compact('document.jsonld', 'context.jsonld'); $framed = JsonLD::frame('document.jsonld', 'frame.jsonld'); $flattened = JsonLD::flatten('document.jsonld'); $quads = JsonLD::toRdf('document.jsonld'); // Output the expanded document (pretty print) print JsonLD::toString($expanded, true); // Serialize the quads as N-Quads $nquads = new NQuads(); $serialized = $nquads->serialize($quads); print $serialized; // And parse them again to a JSON-LD document $quads = $nquads->parse($serialized); $document = JsonLD::fromRdf($quads); print JsonLD::toString($document, true); // Node-centric API $doc = JsonLD::getDocument('document.jsonld'); // get the default graph $graph = $doc->getGraph(); // get all nodes in the graph $nodes = $graph->getNodes(); // retrieve a node by ID $node = $graph->getNode('http://example.com/node1'); // get a property $node->getProperty('http://example.com/vocab/name'); // add a new blank node to the graph $newNode = $graph->createNode(); // link the new blank node to the existing node $node->addPropertyValue('http://example.com/vocab/link', $newNode); // even reverse properties are supported; this returns $newNode $node->getReverseProperty('http://example.com/vocab/link'); // serialize the graph and convert it to a string $serialized = JsonLD::toString($graph->toJsonLd());
sweetrdf/json-ld 适用场景与选型建议
sweetrdf/json-ld 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.87k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2026 年 01 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「JSON-LD」 「jsonld」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sweetrdf/json-ld 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sweetrdf/json-ld 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sweetrdf/json-ld 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Laravel wrapper for torann/json-ld
A tool for scraping URL resources (oEmbed, OpenGraph, Twitter cards, JSON-LD)
SEO Tools for Laravel and Lumen
JSON-LD Processor for PHP
SEO Tools for Laravel and Lumen
A PHP library that validates JSON-LD structured data against the schema.org vocabulary.
统计信息
- 总下载量: 7.87k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 2
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-04