{"id":13405348,"url":"https://github.com/digitalbazaar/php-json-ld","last_synced_at":"2025-04-12T21:19:56.771Z","repository":{"id":56968744,"uuid":"2138378","full_name":"digitalbazaar/php-json-ld","owner":"digitalbazaar","description":"PHP implementation of a JSON-LD Processor and API","archived":false,"fork":false,"pushed_at":"2023-07-15T19:17:49.000Z","size":859,"stargazers_count":278,"open_issues_count":3,"forks_count":42,"subscribers_count":40,"default_branch":"master","last_synced_at":"2024-09-30T22:12:50.074Z","etag":null,"topics":["json-ld","linked-data","php","rdf","semantic-web"],"latest_commit_sha":null,"homepage":"https://github.com/digitalbazaar/php-json-ld","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/digitalbazaar.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2011-08-01T18:49:00.000Z","updated_at":"2024-09-12T10:07:01.000Z","dependencies_parsed_at":"2024-01-18T23:04:51.449Z","dependency_job_id":"15fdd10c-c488-4650-9e3c-086c3148ab39","html_url":"https://github.com/digitalbazaar/php-json-ld","commit_stats":{"total_commits":324,"total_committers":7,"mean_commits":"46.285714285714285","dds":0.04938271604938271,"last_synced_commit":"1f96ec8691c03f4d21d49bd4b23408e8b2a96c59"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digitalbazaar%2Fphp-json-ld","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digitalbazaar%2Fphp-json-ld/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digitalbazaar%2Fphp-json-ld/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/digitalbazaar%2Fphp-json-ld/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/digitalbazaar","download_url":"https://codeload.github.com/digitalbazaar/php-json-ld/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248632158,"owners_count":21136633,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["json-ld","linked-data","php","rdf","semantic-web"],"created_at":"2024-07-30T19:01:59.532Z","updated_at":"2025-04-12T21:19:56.733Z","avatar_url":"https://github.com/digitalbazaar.png","language":"PHP","readme":"php-json-ld\n===========\n\n[![Build Status][travis-ci-png]][travis-ci-site]\n\n[travis-ci-png]: https://travis-ci.org/digitalbazaar/php-json-ld.png?branch=master\n[travis-ci-site]: https://travis-ci.org/digitalbazaar/php-json-ld\n\nIntroduction\n------------\n\nThis library is an implementation of the [JSON-LD][] specification in [PHP][].\n\nJSON, as specified in [RFC7159][], is a simple language for representing\nobjects on the Web. Linked Data is a way of describing content across\ndifferent documents or Web sites. Web resources are described using\nIRIs, and typically are dereferencable entities that may be used to find\nmore information, creating a \"Web of Knowledge\". [JSON-LD][] is intended\nto be a simple publishing method for expressing not only Linked Data in\nJSON, but for adding semantics to existing JSON.\n\nJSON-LD is designed as a light-weight syntax that can be used to express\nLinked Data. It is primarily intended to be a way to express Linked Data\nin JavaScript and other Web-based programming environments. It is also\nuseful when building interoperable Web Services and when storing Linked\nData in JSON-based document storage engines. It is practical and\ndesigned to be as simple as possible, utilizing the large number of JSON\nparsers and existing code that is in use today. It is designed to be\nable to express key-value pairs, RDF data, [RDFa][] data,\n[Microformats][] data, and [Microdata][]. That is, it supports every\nmajor Web-based structured data model in use today.\n\nThe syntax does not require many applications to change their JSON, but\neasily add meaning by adding context in a way that is either in-band or\nout-of-band. The syntax is designed to not disturb already deployed\nsystems running on JSON, but provide a smooth migration path from JSON\nto JSON with added semantics. Finally, the format is intended to be fast\nto parse, fast to generate, stream-based and document-based processing\ncompatible, and require a very small memory footprint in order to operate.\n\n## Quick Examples\n\n```php\n$doc = (object)array(\n  \"http://schema.org/name\" =\u003e \"Manu Sporny\",\n  \"http://schema.org/url\" =\u003e (object)array(\"@id\" =\u003e \"http://manu.sporny.org/\"),\n  \"http://schema.org/image\" =\u003e (object)array(\"@id\" =\u003e \"http://manu.sporny.org/images/manu.png\")\n);\n\n$context = (object)array(\n  \"name\" =\u003e \"http://schema.org/name\",\n  \"homepage\" =\u003e (object)array(\"@id\" =\u003e \"http://schema.org/url\", \"@type\" =\u003e \"@id\"),\n  \"image\" =\u003e (object)array(\"@id\" =\u003e \"http://schema.org/image\", \"@type\" =\u003e \"@id\")\n);\n\n// compact a document according to a particular context\n// see: http://json-ld.org/spec/latest/json-ld/#compacted-document-form\n$compacted = jsonld_compact($doc, $context);\n\necho json_encode($compacted, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);\n/* Output:\n{\n  \"@context\": {...},\n  \"image\": \"http://manu.sporny.org/images/manu.png\",\n  \"homepage\": \"http://manu.sporny.org/\",\n  \"name\": \"Manu Sporny\"\n}\n*/\n\n// compact using URLs\njsonld_compact('http://example.org/doc', 'http://example.org/context');\n\n// expand a document, removing its context\n// see: http://json-ld.org/spec/latest/json-ld/#expanded-document-form\n$expanded = jsonld_expand($compacted) {\necho json_encode($expanded, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);\n/* Output:\n{\n  \"http://schema.org/image\": [{\"@id\": \"http://manu.sporny.org/images/manu.png\"}],\n  \"http://schema.org/name\": [{\"@value\": \"Manu Sporny\"}],\n  \"http://schema.org/url\": [{\"@id\": \"http://manu.sporny.org/\"}]\n}\n*/\n\n// expand using URLs\njsonld_expand('http://example.org/doc');\n\n// flatten a document\n// see: http://json-ld.org/spec/latest/json-ld/#flattened-document-form\n$flattened = jsonld_flatten($doc);\n// all deep-level trees flattened to the top-level\n\n// frame a document\n// see: http://json-ld.org/spec/latest/json-ld-framing/#introduction\n$framed = jsonld_frame($doc, $frame);\n// document transformed into a particular tree structure per the given frame\n\n// normalize a document using the RDF Dataset Normalization Algorithm\n// (URDNA2015), see: http://json-ld.github.io/normalization/spec/\n$normalized = jsonld_normalize(\n  $doc, array('algorithm' =\u003e 'URDNA2015', 'format' =\u003e 'application/nquads'));\n// normalized is a string that is a canonical representation of the document\n// that can be used for hashing, comparison, etc.\n\n// force HTTPS-only context loading:\n// use built-in secure document loader\njsonld_set_document_loader('jsonld_default_secure_document_loader');\n\n// set a default custom document loader\njsonld_set_document_loader('my_custom_doc_loader');\n\n// a custom loader that demonstrates using a simple in-memory mock for\n// certain contexts before falling back to the default loader\n// note: if you want to set this loader as the new default, you'll need to\n// store the previous default in another variable first and access that inside\n// the loader\nglobal $mocks;\n$mocks = array('http://example.com/mycontext' =\u003e (object)array(\n  'hombre' =\u003e 'http://schema.org/name'));\nfunction mock_load($url) {\n  global $jsonld_default_load_document, $mocks;\n  if(isset($mocks[$url])) {\n    // return a \"RemoteDocument\", it has these three properties:\n    return (object)array(\n      'contextUrl' =\u003e null,\n      'document' =\u003e $mocks[$url],\n      'documentUrl' =\u003e $url);\n  }\n  // use default loader\n  return call_user_func($jsonld_default_load_document, $url);\n}\n\n// use the mock loader for just this call, witout modifying the default one\n$compacted = jsonld_compact($foo, 'http://example.com/mycontext', array(\n  'documentLoader' =\u003e 'mock_load'));\n\n// a custom loader that uses a simplistic in-memory cache (no invalidation)\nglobal $cache;\n$cache = array();\nfunction cache_load($url) {\n  global $jsonld_default_load_document, $cache;\n  if(isset($cache[$url])) {\n    return $cache[$url];\n  }\n  // use default loader\n  $doc = call_user_func($jsonld_default_load_document, $url);\n  $cache[$url] = $doc;\n  return $doc;\n}\n\n// use the cache loader for just this call, witout modifying the default one\n$compacted = jsonld_compact($foo, 'http://schema.org', array(\n  'documentLoader' =\u003e 'cache_load'));\n```\n\nCommercial Support\n------------------\n\nCommercial support for this library is available upon request from\n[Digital Bazaar][]: support@digitalbazaar.com\n\nSource\n------\n\nThe source code for the PHP implementation of the JSON-LD API\nis available at:\n\nhttp://github.com/digitalbazaar/php-json-ld\n\nTests\n-----\n\nThis library includes a sample testing utility which may be used to verify\nthat changes to the processor maintain the correct output.\n\nTo run the sample tests you will need to get the test suite files by cloning\nthe `json-ld.org` and `normalization` repositories hosted on GitHub:\n\n- https://github.com/json-ld/json-ld.org\n- https://github.com/json-ld/normalization\n\nThen run the PHPUnit test.php application and point it at the directories\ncontaining the tests:\n\n    phpunit --group json-ld.org test.php -d {PATH_TO_JSON_LD_ORG/test-suite}\n    phpunit --group normalization test.php -d {PATH_TO_NORMALIZATION/tests}\n\n[Digital Bazaar]: http://digitalbazaar.com/\n[JSON-LD]: http://json-ld.org/\n[Microdata]: http://www.w3.org/TR/microdata/\n[Microformats]: http://microformats.org/\n[PHP]: http://php.net\n[RDFa]: http://www.w3.org/TR/rdfa-core/\n[RFC7159]: http://tools.ietf.org/html/rfc7159\n","funding_links":[],"categories":["PHP","Implementations"],"sub_categories":["PHP"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdigitalbazaar%2Fphp-json-ld","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdigitalbazaar%2Fphp-json-ld","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdigitalbazaar%2Fphp-json-ld/lists"}