Devel::JSON - Easy JSON output for one-liners
$ perl -d:JSON -e '[ 1..3 ]' [ 1, 2, 3 ] $ perl -d:JSON -e '{b => 2, c => 4}' { "b": 2, "c": 4 }
Default output encoding is UTF-x if this is the charset of the locale:
$ perl -d:JSON -e "qq<\N{SNOWMAN}>" "☃"
Force ASCII output:
$ perl -d:JSON=ascii -e "qq<\N{SNOWMAN}>" "\u2603"
Booleans:
$ perl -d:JSON -MJSON::PP -e 'JSON::PP::true' true
If you use this module from the command-line, the last value of your one-liner (-e) code will be serialized as JSON data. The expression is evaluated in scalar context.
-e
The output will be either UTF-x (UTF-8, UTF-16...) or just ASCII, depending on your locale (check LC_CTYPE on Unix or GNU).
LC_CTYPE
As a convenience (because you may want to deal with non-ASCII content in your -e source), your code is converted from bytes using the current locale.
The following JSON options are enabled by default:
pretty
canonical
allow_nonref
You can enable more options by giving import arguments (a '-' prefix disables the option):
# Force ASCII output $ perl -d:JSON=ascii -e '[1..3]' # Disable pretty (note '-' before the name) $ perl -d:JSON=-pretty -e '[1..3]' # Non-ASCII in -e $ perl -d:JSON=ascii -e '"Mengué"' "Mengu\u00e9"
JSON, JSON::MaybeXS, json-to (App::JSON::to).
Olivier Mengué, mailto:dolmen@cpan.org.
Copyright © 2017 Olivier Mengué.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Devel::JSON, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Devel::JSON
CPAN shell
perl -MCPAN -e shell install Devel::JSON
For more information on module installation, please visit the detailed CPAN module installation guide.