phphleb/nicejson

Convert json to readable form

Maintainers

Details

github.com/phphleb/nicejson

Source

Installs: 3 848

Dependents: 5

Suggesters: 0

Security: 0

Stars: 1

Watchers: 1

Forks: 0

pkg:composer/phphleb/nicejson

1.0.0 2024-02-06 21:33 UTC

This package is auto-updated.

Last update: 2025-10-06 02:19:00 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);