NAME : re-format JSON data


Version 0.25

SYNOPSIS -i "input.json" -o "output.json" --escape-unicode --pretty -e < "input.json" > "output.json"

    # press CTRL-D when done typing JSON to STDIN
    # input must be less than 4K long!

    # 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)) -e < $(xclip -o) -e < $(pbaste)
    # write the output to the clipboard for further pasting -i input.json | xclip -i
    # clicking mouse's middle-button will paste the result



  • --i filename : specify a filename which contains a JSON data structure.

  • --I "string" : specify a string which contains a JSON data structure.

  • --o outputfilename : specify the output filename to write the result to, which will be the reformatted JSON.

  • --escape-unicode : it will escape all unicode characters, and convert them to something like "\u0386". This is the default option.

  • --no-escape-unicode : it will NOT escape unicode characters. Output will not contain "\u0386" or "\x{386}" but "α" (that's a greek alpha). This is the default option.

  • --pretty / --no-pretty : write this JSON pretty, line breaks, indendations, "the full catastrophe". The second is the default.

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 < inputfile.json > outputfile.json

For more information see Data::Roundtrip.


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.


Andreas Hadjiprocopis, <bliako at> / <andreashad2 at>