JSON-JSONFold
view release on metacpan or search on metacpan
# JSON::JSONFold
Readable, compact JSON formatting for Perl.
JSON::JSONFold is a streaming JSON formatter that produces compact,
human-readable output by selectively folding small arrays and objects.
## Installation
```sh
cpanm JSON::JSONFold
```
## Example
```perl
use JSON::JSONFold qw(encode_json);
my $data = {
ids => [
1,
2,
3,
4
],
meta => {
version => 1,
ok => 1
},
};
print encode_json($data);
```
Default output (`default` preset):
```json
{
"ids": [ 1, 2, 3, 4, 5, 6 ],
"items": [
{ "id": 1, "name": "alpha" }, { "id": 2, "name": "beta" }
],
"long_array": [
"a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8",
"a9", "a10",
],
"matrix": [
[ 1, 2 ], [ 3, 4 ], [ 5, 6 ]
],
"meta": { "name": "jsonfold demo", "ok": true, "version": 1 },
}
```
More compact output (`max` preset):
```perl
use JSON::JSONFold qw(config encode_json);
my $cfg = config(
compact => "max",
width => 120,
);
print encode_json($data, $cfg);
```
( run in 0.566 second using v1.01-cache-2.11-cpan-140bd7fdf52 )