81
Gcir
3y

Tip: pretty print json file using:

cat file.json | python -m json.tool

Comments
  • 12
    Wow, that's like... an actual great tip!
    Thanks bud & Welcome
  • 2
    @Kimmax cheers ;)
  • 4
    Alias created, thanks dude
  • 8
    Please, don't use cat to pipe file contents. Use <.
  • 2
    @IllSlapU because cat is for concatenating files, not printing to stdout. It is misused daily.
  • 3
    And add a -n to cat for line numbers
  • 4
    @inaba if you add -n well stdout ain't json anymore.
  • 5
    @kpenc I'm going to keep doing it just to annoy people like you.
  • 2
    You forgot something important there

    | lolcat
  • 1
    How to do it in Windows? I don't have cats.

    Good tip though, guess I can just read the usage docs...
  • 2
    @Zaphod65 do whatever you like. Reasoning at it's finest.
  • 3
    @billgates there is GNU coreutils for win32 if you want to use cat
  • 5
    And there's also jq regardless of platform.
  • 3
    @billgates using cat or not is pointless. json.tool reads stdin
  • 3
    @billgates I use WSL (bash on windows) on Windows. It can mix windows and Linux commands
  • 1
    Nice command. When I needed such a thing, I used the Dev-Tools in my browser to pretty print it.
    Console solutions are still the best. 👍
  • 2
    Yeah, seems like a lot of work to avoid using jq.
  • 2
    For JSON formatting, processing and querying using bash or powershell, I recommend jq (https://stedolan.github.io/jq). It's such an amazing library. It allows you quickly operate over any JSON.
  • 4
    The real question here is whether a python would eat a cat and also which one of the two is called Jason...
  • 1
    @marcus5914 yes maybe I could enable that again but that takes like 5gb...
  • 1
    Well I am a simple man I use a sublime extension
  • 0
    @arpit1997 all very well and good if you have access to sublime, but I've used the python tool over SSH on servers many times, it makes that whole process so much easier!
  • 1
    @Zaphod65 no no I completely agree with him and it's a great tip but I said simple man simple things. Never has to prettify a JSON over remote server
  • 1
    @arpit1997 then you're a pretty lucky man as well, by my estimation! xD
Add Comment