NAME
Test::JSON::Entails - Test whether one JSON structure entails another
VERSION
version 0.1
SYNOPSIS
use Test::JSON::Entails;
entails $json, { foo => 1 }, "JSON contains a foo element with value 1";
entails $json, '{}', "JSON is a valid JSON object (no array)";
DESCRIPTION
Sometimes you want to compare JSON objects not for exact equivalence but for whether one structure subsumes the other. The other way round, one structure can be entailed by another. For instance
{ "foo": 1, "bar": [ "x" }
is entailed by any of the following structures:
{ "foo": 1, "bar": [ "x" ], "doz": 2 } # additional hash element
{ "foo": 1, "bar": [ "x", "y" ], "doz": 2 } # additional array element
This module exports the testing method entails
to check such entailments. You can pass both, JSON strings with encoded JSON objects, and Perl hash references.
LIMITATIONS
This module does not distinguish between numbers and strings, neither between true and 1 or false and 0. Circular references in passed objects are not detected.
SEE ALSO
This module reuses some code from Test::JSON, created by Curtis "Ovid" Poe. If you need more granular comparision of data structures, you should better use Test::Deep.
AUTHOR
Jakob Voss
COPYRIGHT AND LICENSE
This software is copyright (c) 2011 by Jakob Voss.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.