NAME

perl2json.pl : convert a Perl data structure dump to JSON

VERSION

Version 0.22

SYNOPSIS

perl2json.pl -i "perl-data-structure.pl" -o "output.json" --escape-unicode --pretty

perl2json.pl -e < "perl-data-structure.pl" > "output.json"

# press CTRL-D when done typing json to STDIN
# input must be less than 4K long!
perl2json.pl

# Read input from clipboard or write output to clipboard
# Only in: Unix / Linux / OSX                
# (must have already installed xclip or xsel or pbpaste (on OSX))
json2json.pl -e < $(xclip -o)
json2json.pl -e < $(pbaste)
# write the output to the clipboard for further pasting
json2json.pl -i input.json | xclip -i
# clicking mouse's middle-button will paste the result

USAGE

perl2json.pl

Options:

  • --i filename : specify a filename which contains a Perl data structure in text representation, not as a (binary) serialised object, as one would have used in a Perl script.

  • --I "string" : specify a string which contains a Perl data structure in text representation, not as a (binary) serialised object. But exactly as one would have used in a Perl script.

  • --o outputfilename : specify the output filename to write the result to.

  • --escape-unicode / --no-escape-unicode : it will escape all unicode characters, and convert them to something like "\u0386"

  • --pretty / --no-pretty : write this JSON pretty, line breaks, indendations, "the full catastrophe"

Input can be read from an input file (--i), from a string at the command line (--I) (properly quoted!), from STDIN (which also includes a file redirection json2json.pl < inputfile.json > outputfile.json

For more information see Data::Roundtrip.

CAVEATS

Under Unix/Linux, the maximum number of characters that can be read on a terminal is 4096. So, in reading-from-STDIN mode beware how much you type or how much you copy-paste onto the script. If it complains about malformed input then this is the case. The workaround is to type/paste onto a file and operate on that using --i afile or redirection < afile.

AUTHOR

Andreas Hadjiprocopis, <bliako at cpan.org> / <andreashad2 at gmail.com>