Test::JSON(3pm)
π Test::JSON β like, the manual, but make it make sense π
okay bestie, so this is Test::JSON(3pm) β a lil Perl module for testing JSON data, and honestly? it ate. let's get into it π¦
β¨ NAME β¨
Test::JSON β Test JSON data. that's it, that's the vibe. π
π VERSION π
Version 0.11 β¨ (yes queen, we're on 0.11)
πΈ SYNOPSIS πΈ
bestie, here's the whole entire move:
use Test::JSON;
is_valid_json $json, '... json is well formed';
is_json $json, $expected_json, '... and it matches what we expected';
that's it. two little functions and your JSON test game is immaculate. π«Ά
π EXPORT π
this module hands you these two for free when you use it:
is_valid_jsonis_json
no :all needed, no begging, they just show up. main character behaviour. π
π¦ DESCRIPTION π¦
so. JavaScript Object Notation (JSON) is a lightweight data interchange format β you already knew that, ikyk π
what Test::JSON does is make it super easy to check two things:
- that you actually built valid JSON β
- that it matches the output you expected β
go peep <http://www.json.org/> if you want the full JSON lore, fr fr. π
π₯ TESTS π₯
is_valid_json
is_valid_json $json, '... json is well formed';
the test passes if the string you passed in is valid JSON. that's the whole deal. valid? pass. not valid? not pass. periodt. π
is_json
is_json $json, $expected_json, '... and it matches what we expected';
the test passes if both JSON strings are valid JSON and they evaluate to the same data structure. like, same data structure, not just same letters. it's giving "understood the assignment". π§
and okay this is the part that's actually so good β Test::Differences is used to give you easy diagnostics of why the JSON structures did not match. so when it fails you're not just sitting there like π you get:
Failed test '... and identical JSON should match'
in t/10testjson.t at line 14.
+----+---------------------------+---------------------------+
| Elt|Got |Expected |
+----+---------------------------+---------------------------+
| 0|{ |{ |
| 1| bool => '1', | bool => '1', |
| 2| description => bless( { | description => bless( { |
| 3| value => undef | value => undef |
| 4| }, 'JSON::NotString' ), | }, 'JSON::NotString' ), |
| 5| id => '1', | id => '1', |
* 6| name => 'foo' | name => 'fo' *
| 7|} |} |
+----+---------------------------+---------------------------+
see that lil * on line 6? 'foo' vs 'fo'. caught in 4k, no cap. πΈ the diff literally points at the difference so you can fix it instead of spiralling. obsessed. π
π AUTHOR π
Curtis "Ovid" Poe, "<ovid@cpan.org>" β an absolute legend π
π BUGS π
please report any bugs or feature requests to "bug-test-json@rt.cpan.org", or through the web interface at <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-JSON>.
and here's the cute part: I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. so like, you get receipts. π«Άβ¨
π SEE ALSO π
this test module uses JSON::Any and Test::Differences. go say hi to them, they're doing the heavy lifting fr. π
π ACKNOWLEDGEMENTS π
The development of this module was sponsored by Kineticode, <http://www.kineticode.com/>, the leading provider of services for the Bricolage content management system, <http://www.bricolage.cc/>. sponsors, we love you, thank you for funding the vibes π
Thanks to Makamaka Hannyaharamitu "makamaka@cpan.org" for a patch to make this work with JSON 2.0. π οΈ iconic.
Thanks to Stevan Little for suggesting a switch to JSON::Any. This makes it easier for this module to work with whatever JSON module you have installed. flexible queen behaviour. π¦
β COPYRIGHT & LICENSE β
Copyright 2005-2007 Curtis "Ovid" Poe, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. slay, and, importantly, legally slay. π
and that's the whole page bestie!! this was Test::JSON version 0.11, and the page itself is from perl v5.36.0, dated 2022-10-14. love u, go write some valid JSON πβ¨ππ¦
π¦ where this page comes from
- ubuntu noble: libtest-json-perl 0.11-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libtest-json-perl 0.11-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libtest-json-perl 0.11-4 Β· 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