dev-master
9999999-dev https://github.com/LukasRos/JSONInclude-PHPCombine JSON data from multiple files.
MPL
The Requires
- php >=5.3.0
json
Wallogit.com
2017 © Pedro Peláez
Combine JSON data from multiple files.
XML has XInclude which allows to combine XML from different files into one. There is no generic equivalent for JSON that I am aware of, so I came up with a simple idea for it. I believe having this can be useful if we want to dynamically combine JSON output, e.g. in an API, from different static files without duplicating information in those files., (*1)
Let's explain it with an example ... assume we have one file:, (*2)
{
"key1" : "value1",
"key2" : "@file2.txt"
}
The "@" is an include symbol which indicates the string behind it should be treated as the filename for inclusion. The content of the second file is this:, (*3)
{
"key1" : "value2"
}
Loading the first file with a JSONInclude parser would return the following output:, (*4)
{
"key1" : "value1",
"key2" : {
"key1" : "value2"
}
}
The include symbol can also be changed in case a leading "@" is used for a different purpose., (*5)
A simple parser for JSONInclude as a reference implementation written in PHP. It also supports parsing JSON files with comments and generic preprocessing of JSON data., (*6)
"lukasros/json-include": "dev-master" to the composer.json file for your project.$jsonInclude = new LukasRos\JSONInclude\JSONInclude();
$parsedJson = $jsonInclude->parseFileWithIncludes('filename.json');
Please check the demo folder for an example., (*7)
JSONInclude-PHP was created by Lukas Rosenstock. Contact me through my website at lukasrosenstock.net., (*8)
This software is released under the MPL - see LICENSE file for details., (*9)
Combine JSON data from multiple files.
MPL
json