https://github.com/sgpinkus/jsonref
A PHP JsonRef de-referencer
https://github.com/sgpinkus/jsonref
Last synced: 9 months ago
JSON representation
A PHP JsonRef de-referencer
- Host: GitHub
- URL: https://github.com/sgpinkus/jsonref
- Owner: sgpinkus
- Created: 2016-10-30T06:19:55.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2021-05-02T00:28:53.000Z (over 4 years ago)
- Last Synced: 2025-02-13T14:18:03.999Z (11 months ago)
- Language: PHP
- Homepage:
- Size: 149 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# PHP JSONREF
This library implements [JSON Reference v0.4.0](http://jsonref.org) and by extension [JSON Pointer](https://tools.ietf.org/html/draft-ietf-appsawg-json-pointer-04) (JSON Reference requires JSON Pointer) for PHP. JSON Reference v0.4.0 succeeds [JSON Reference v0.3.0](https://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03) and is *not* entirely backwards compatible.
This library replaces JSON references in a JSON document with native PHP references to parts of the same decoded JSON document, or parts of some other decoded JSON document referred to by URI. It supports doing this on an existing decoded JSON document data structures, or loading and decoding the JSON document from a URL.
*NOTE: Pre-encode, normalization of objects is not yet supported.*
# INSTALLATION
```
composer install
```
# TESTS
```
composer test
```
# SYNOPSIS
The following show various ways of loading and dereferencing a JSON document:
```
loadUri($myUri);
var_dump($doc);
$doc2 = $jsonDocs->loadUri($myUri);
var_dump($doc === $doc2); // true
$strDoc = file_get_contents(realpath('./tests/test-data/basic-refs.json'));
$doc = $jsonDocs->loadDocStr($strDoc, 'file:///tmp/some/fake/unique/path');
var_dump($doc);
// Or if the doc is already decoded.
$objDoc = json_decode($strDoc);
$doc = $jsonDocs->loadDocObj($objDoc, 'file:///tmp/some/fake/unique/path2');
var_dump($doc);
```