Badger...c::JSON(3pm)
β¨ NAME β¨
Badger::Codec::JSON β bestie, this is the one that encodes and decodes your data using JSON π
It lives in the User Contributed Perl Documentation section of the manual, section 3pm, iykyk π
π¦ SYNOPSIS π¦
okay so literally the whole vibe in four lines:
use Badger::Codec::JSON;
my $codec = Badger::Codec::JSON->new();
my $encoded = $codec->encode({ msg => "Hello World" });
my $decoded = $codec->decode($encoded);
look at her go π encode a hash, get a string, decode the string, get your hash back. main character behaviour fr fr.
πΈ DESCRIPTION πΈ
So this module implements a subclass of Badger::Codec β and the way that it works is it uses the JSON::XS or JSON module (whichever one you happen to have installed, no pressure, she'll take either π«Ά) to encode and decode data to and from JSON.
And honestly? It's little more than an adapter module to fit JSON into the Badger::Codec mould. That's it. That's the whole job. She's not trying to be extra, she's just making JSON wear the Badger::Codec fit and she ate. β¨
π METHODS π
π encode($data)
Encodes the Perl data sitting in $data into a JSON string. This method is a lil wrapper around the internal encode_json() subroutine. π
$encoded = Badger::Codec::JSON->encode($data);
π decode($json)
Takes the encoded JSON string in $json and decodes it right back into a Perl data structure. This one is a wrapper around the internal decode_json() subroutine. π₯
$decoded = Badger::Codec::JSON->decode($encoded);
π encoder()
This method returns a reference to the real subroutine that's doing all the encoding work β and that's the internal encode_json() subroutine. she's the one behind the scenes carrying the whole operation ngl π
π decoder()
This method returns a reference to the real subroutine doing all the decoding work, i.e. the decode_json() subroutine in JSON. periodt. π
π§ INTERNAL SUBROUTINES π§
β encode_json($data)
This is the internal subroutine that encodes the JSON data. It delegates to the JSON::XS or JSON module, depending on which one you have installed. lowkey she's just passing the aux cord π§
β decode_json($json)
This is the internal subroutine that decodes the JSON data. As per encode_json(), it delegates the task to the JSON::XS or JSON module. same energy, opposite direction, we love a consistent queen π¦
π AUTHOR π
Andy Wardley <http://wardley.org/>
π COPYRIGHT π
Copyright (C) 2005-2009 Andy Wardley. All rights reserved.
π SEE ALSO π
- Badger::Codecs
- Badger::Codec
- JSON
and that's the whole page bestie π this one shipped as part of perl v5.36.0, dated 2023-08-28, under the Badger...c::JSON(3pm) banner β go forth and encode, you've got this π«Άβ¨π
π¦ where this page comes from
- debian trixie: libbadger-perl 0.16-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libbadger-perl 0.16-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libbadger-perl 0.16-3 Β· 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