The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Test::JSON::More - JSON Test Utility

SYNOPSIS

    use Test::JSON::More;
    use Test::More;

    my $json = '{"foo":123,"bar":"baz"}';

    ok_json($json);

    cmp_json($json, '{"bar":"baz","foo":123}');

    my $schema = {
        type       => "object",
        properties => {
            foo => { type => "integer" },
            bar => { type => "string" }
        },
        required => [ "foo" ]
    };

    ok_json_schema($json, $schema);

    is parsed_json->{foo}, 123;

    done_testing;

DESCRIPTION

Test::JSON::More is the utility for testing JSON string.

SWITCH JSON MODULES

By default, Test::JSON::More use JSON module for encoding/decoding JSON. If you would like to use an another JSON module in the test, then you can specify it at loading Test::JSON::More, like below.

    use Test::JSON::More 'JSON::XS';

NOTE that the switching JSON module needs to implement new, encode and decode methods.

METHODS

ok_json

    ok_json($json, $test_name)

Test passes if the string is valid JSON.

cmp_json

    cmp_json($json, $expected_json, $test_name)

Test passes if the two JSON strings are valid JSON and evaluate to the same data structure.

ok_json_schema

    ok_json_schema($json, $schema, $test_name)

Test passes if the string is valid JSON and fits the schema againsts its specification.

$schema is a perl hash reference or a string of JSON schema, whichever is OK.

parsed_json

    $ref = parsed_json();

The parsed_json function returns the perl hash ref or array ref that is the result of parsed JSON in a test methods(i.e. ok_json, cmp_json or ok_json_schema).

REPOSITORY

Test::JSON::More is hosted on github: http://github.com/bayashi/Test-JSON-More

I appreciate any feedback :D

AUTHOR

Dai Okabayashi <bayashi@cpan.org>

SEE ALSO

JSON validator: JSV::Validator, JSV

Test builder: Test::Builder::Module

Inspired by Test::JSON

LICENSE

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.