Badger...c::JSON(3pm)

πŸ“¦
version 0.16 Β· 4 versions
, in debian trixie, ubuntu noble, ubuntu resolute

✨ 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 (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