https://github.com/phphleb/nicejson
Convert json to readable form
https://github.com/phphleb/nicejson
Last synced: 4 months ago
JSON representation
Convert json to readable form
- Host: GitHub
- URL: https://github.com/phphleb/nicejson
- Owner: phphleb
- License: mit
- Created: 2020-11-17T09:49:56.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2024-12-06T00:28:51.000Z (over 1 year ago)
- Last Synced: 2025-10-10T16:54:34.507Z (8 months ago)
- Language: PHP
- Homepage:
- Size: 7.81 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
NICEJSON
=====================
[](https://github.com/phphleb/hleb) [](https://github.com/phphleb/hleb)  [-brightgreen.svg)](https://github.com/phphleb/hleb/blob/master/LICENSE)
[Previous code]() for PHP version < 8.2
### Convert json to readable form
Install using Composer:
```bash
composer require phphleb/nicejson
```
-----------------------------------------
Convert
```json
{"example":["first","second"]}
```
to
```json
{
"example": [
"first",
"second"
]
}
```
```php
$data = '{"example":["first","second"]}'; // string json
file_put_contents('/path/to/result/json/file/', (new \Phphleb\Nicejson\JsonConverter())->get($data));
```
or
```php
$data = ["example"=>["first","second"]]; // array
file_put_contents('/path/to/result/json/file/', (new \Phphleb\Nicejson\JsonConverter())->get($data));
```
or
```php
$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(...)
```php
use Phphleb\Nicejson\JsonConverter;
$jsonConverterObject = new JsonConverter(JSON_FORCE_OBJECT);
```