JSON::...Compact(3pm)
π NAME π
JSON::Dumper::Compact β JSON processing with Data::Dumper::Compact aesthetics. It's giving glow-up, honestly.
β¨ SYNOPSIS β¨
use JSON::Dumper::Compact 'jdc';
my $json = jdc($data);
okay so that's literally it, bestie. one import, one call. π
π¦ DESCRIPTION π¦
JSON::Dumper::Compact is a subclass of Data::Dumper::Compact that turns arrayrefs and hashrefs instead into JSON. same iconic energy, different outfit. π
Deep data structures are rendered highly compactly, like:
[
"1556933590.65383", "Fri May 3 18:33:10 2019", 26794, "INFO", 3,
[ "SRV:8FB66F32" ], [ [
"/opt/voice-srvc-native/bin/async-srvc-att-gateway-poller", 33,
"NERV::Voice::SRV::Native::AsyncSRVATTGatewayPoller::main",
] ],
"batch_nena_messages returned", "OK", 6, { "FILENAME": "lqxw020323" },
1556933584, "lqxw020323",
]
To ease debugging, blessed references without a "TO_JSON" method are rendered as an object with a single two-element arrayref value:
{ "__bless__": [
"The::Class",
{ "the": "object" },
] }
ngl that __bless__ trick is so smart, it ate and left no crumbs π
πΈ METHODS πΈ
In addition to the Data::Dumper::Compact methods, we provide:
π« encode
JSON::Dumper::Compact->encode($data, \%opts?);
$jdc->encode($data, \%opts?);
Operates identically to "dump" in Data::Dumper::Compact but named to be less confusing to code expecting a JSON object. same behavior, better name, main character rebrand. β¨
π« decode
JSON::Dumper::Compact->decode($string, \%opts?);
$jdc->decode($string, \%opts);
Runs the supplied string through an JSON::MaybeXS "decode" with options set to be able to reliably reparse what we can currently format β notably setting "relaxed" to allow for trailing commas and using "filter_json_single_key_object" to re-inflate blessed objects. yep, it even handles the trailing commas, no cap. π«Ά
β οΈ Note that using this method on untrusted data is a security risk. While"encode"/"dump"should be usable for JSON formatting, in general,"decode"fully rehydrates for debugging purposes and as such can e.g. cause DESTROY methods to be called unexpectedly, which can allow a malicious user to do things to your perl5 VM. Rather than using debugging specific code on untrusted data, use JSON::MaybeXS or Mojo::JSON directly (if the"encode"output doesn't parse correctly via other libraries, please report that as a bug)..
π DO NOT USE THIS METHOD ON UNTRUSTED DATA IT WAS NOT DESIGNED TO BE SECURE.
like fr fr, bestie, read that twice. it is ALL CAPS for a reason. ππ
π COPYRIGHT π
Copyright (c) 2019 the "AUTHOR" in Data::Dumper::Compact and "CONTRIBUTORS" in Data::Dumper::Compact as listed in Data::Dumper::Compact.
π LICENSE π
This library is free software and may be distributed under the same terms as perl itself. See <https://dev.perl.org/licenses/>.
and that's a wrap! π this page is from the perl v5.36.0 docs, dated 2022-10-04, and it lives under the manual name JSON::...Compact(3pm) β go forth and dump some compact JSON, you've got this βπ§
π¦ where this page comes from
- ubuntu noble: libdata-dumper-compact-perl 0.006000-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libdata-dumper-compact-perl 0.006000-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libdata-dumper-compact-perl 0.006000-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms