phphleb/nicejson

Convert json to readable form

dev-main 2024-02-06 21:33 UTC

This package is auto-updated.

Last update: 2024-04-06 21:51:06 UTC


README

HLEB1 HLEB2 PHP License: MIT

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);