1Test::JSON(3) User Contributed Perl Documentation Test::JSON(3)
2
3
4
6 Test::JSON - Test JSON data
7
9 Version 0.11
10
12 use Test::JSON;
13
14 is_valid_json $json, '... json is well formed';
15 is_json $json, $expected_json, '... and it matches what we expected';
16
18 · is_valid_json
19
20 · is_json
21
23 JavaScript Object Notation (JSON) is a lightweight data interchange
24 format. Test::JSON makes it easy to verify that you have built valid
25 JSON and that it matches your expected output.
26
27 See <http://www.json.org/> for more information.
28
30 is_valid_json
31 is_valid_json $json, '... json is well formed';
32
33 Test passes if the string passed is valid JSON.
34
35 is_json
36 is_json $json, $expected_json, '... and it matches what we expected';
37
38 Test passes if the two JSON strings are valid JSON and evaluate to the
39 same data structure.
40
41 Test::Differences is used to provide easy diagnostics of why the JSON
42 structures did not match. For example:
43
44 Failed test '... and identical JSON should match'
45 in t/10testjson.t at line 14.
46 +----+---------------------------+---------------------------+
47 | Elt|Got |Expected |
48 +----+---------------------------+---------------------------+
49 | 0|{ |{ |
50 | 1| bool => '1', | bool => '1', |
51 | 2| description => bless( { | description => bless( { |
52 | 3| value => undef | value => undef |
53 | 4| }, 'JSON::NotString' ), | }, 'JSON::NotString' ), |
54 | 5| id => '1', | id => '1', |
55 * 6| name => 'foo' | name => 'fo' *
56 | 7|} |} |
57 +----+---------------------------+---------------------------+
58
60 Curtis "Ovid" Poe, "<ovid@cpan.org>"
61
63 Please report any bugs or feature requests to
64 "bug-test-json@rt.cpan.org", or through the web interface at
65 http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-JSON
66 <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-JSON>. I will be
67 notified, and then you'll automatically be notified of progress on your
68 bug as I make changes.
69
71 This test module uses JSON::Any and Test::Differences.
72
74 The development of this module was sponsored by Kineticode,
75 <http://www.kineticode.com/>, the leading provider of services for the
76 Bricolage content management system, <http://www.bricolage.cc/>.
77
78 Thanks to Makamaka Hannyaharamitu "makamaka@cpan.org" for a patch to
79 make this work with JSON 2.0.
80
81 Thanks to Stevan Little for suggesting a switch to JSON::Any. This
82 makes it easier for this module to work with whatever JSON module you
83 have installed.
84
86 Copyright 2005-2007 Curtis "Ovid" Poe, all rights reserved.
87
88 This program is free software; you can redistribute it and/or modify it
89 under the same terms as Perl itself.
90
91
92
93perl v5.12.0 2009-08-09 Test::JSON(3)