JSON::Color - Encode to colored JSON
This document describes version 0.130 of JSON::Color (from Perl distribution JSON-Color), released on 2020-06-09.
use JSON::Color qw(encode_json);
say encode_json([1, "two", {three => 4}]);
This module generates JSON, colorized with ANSI escape sequences.
To change the color, see the %theme in the source code. In theory you can
also modify it to colorize using HTML.
Encode to JSON. Will die on error (e.g. when encountering non-encodeable data
like Regexp or file handle).
Known options:
Use JSON.
Use the Data::Clean::JSON manpage.
Example:
% perl -MJSON::Color=encode_json -E'say encode_json([1, "1"])'
["1","1"]
To detect whether a scalar is a number (e.g. differentiate between ``1'' and 1),
the XS module the Scalar::Util::LooksLikeNumber manpage is used. This is set as an
optional prerequisite, so you'll need to install it separately. After the
prerequisite is installed:
% perl -MJSON::Color=encode_json -E'say encode_json([1, "1"])'
[1,"1"]
Set default color theme. Has precedence over COLOR_THEME.
Set default color theme.
Please visit the project's homepage at https://metacpan.org/release/JSON-Color.
Source repository is at https://github.com/perlancar/perl-JSON-Color.
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=JSON-Color
When submitting a bug or request, please include a test-file or a
patch to an existing test-file that illustrates the bug or desired
feature.
To colorize with HTML, you can try the Syntax::Highlight::JSON manpage.
the Syntax::SourceHighlight manpage can also colorize JSON/JavaScript to HTML or ANSI
escape. It requires the GNU Source-highlight library.
perlancar <perlancar@cpan.org>
This software is copyright (c) 2020, 2016, 2015, 2014, 2012 by perlancar@cpan.org.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
|