NAME

Mango::BSON::Dump - Helpers to dump Mango BSON documents as Extended JSON

VERSION

version 0.2

SYNOPSIS

use Mango::BSON ':bson';
use Mango::BSON::Dump qw(to_extjson);

#  '{"v":{"$numberLong":"42"},"created":{"$date":"1970-01-01T00:00:00Z"}}'
to_extjson(bson_doc(v => bson_int64(42), created => bson_time(0)));

use Mojo::JSON qw(encode_json);

#  '{"v":{"$numberLong":"42"},"created":{"$date":"1970-01-01T00:00:00Z"}}'
encode_json(bson_doc(v => bson_int64(42), created => bson_time(0)));

DESCRIPTION

This module enables dumping Mango BSON documents and objects as Extended JSON (see https://docs.mongodb.com/manual/reference/mongodb-extended-json/), which might be handy for development and debugging.

FUNCTIONS

to_extjson
$json = to_extjson($bson_doc);
$json = to_extjson($bson_doc, pretty => 1);

Encodes $bson_doc into Extended JSON.

CAVEATS

This module installs TO_JSON methods to a number of packages (eg. Mango::BSON::Number, Mango::BSON::ObjectID, Regexp). This does not play well with other modules defining or installing the same methods to the same classes. As of Mango 1.29, this clashes with defined TO_JSON for Mango::BSON::Binary, Mango::BSON::Number, and Mango::BSON::Time (which don't conform to Extended JSON).

SEE ALSO

https://docs.mongodb.com/manual/reference/mongodb-extended-json/

https://docs.mongodb.com/manual/reference/bson-types/

http://bsonspec.org/

https://github.com/mongodb/specifications/tree/master/source/bson-corpus

ACKNOWLEDGMENTS

The development of this library has been partially sponsored by Connectivity, Inc.

AUTHOR

Adriano Ferreira <ferreira@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2016 by Adriano Ferreira.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.