phphleb / nicejson
Convert json to readable form
1.0.0
2024-02-06 21:33 UTC
Requires
- php: >=8.2.0
- ext-json: *
README
Previous code for PHP version < 8.2
Convert json to readable form
Install using Composer:
composer require phphleb/nicejson
Convert
{"example":["first","second"]}
to
{ "example": [ "first", "second" ] }
$data = '{"example":["first","second"]}'; // string json file_put_contents('/path/to/result/json/file/', (new \Phphleb\Nicejson\JsonConverter())->get($data));
or
$data = ["example"=>["first","second"]]; // array file_put_contents('/path/to/result/json/file/', (new \Phphleb\Nicejson\JsonConverter())->get($data));
or
$data = (object) ["example"=>["first","second"]]; // object file_put_contents('/path/to/result/json/file/', (new \Phphleb\Nicejson\JsonConverter())->get($data));
add flag to json_encode(...)
use Phphleb\Nicejson\JsonConverter; $jsonConverterObject = new JsonConverter(JSON_FORCE_OBJECT);