TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Easy CLI JSON Formatting

33 pointsby subliminoover 12 years ago

9 comments

bryanlarsenover 12 years ago
Couple dozen other ways to do it: <a href="http://stackoverflow.com/questions/352098/how-to-pretty-print-json-script/5006476" rel="nofollow">http://stackoverflow.com/questions/352098/how-to-pretty-prin...</a>
cobralibreover 12 years ago
A problem with piping curl output through "python -mjson.tool" is that you can't include the response headers, which is sometimes useful.<p>(This was enough of a problem for me that I wrote a simple curl replacement in Python so I could have pretty-printed JSON or XML <i>and</i> response headers, <i>or</i> send the response directly to a Python REPL console as an object: <a href="https://github.com/cobralibre/hotpotato" rel="nofollow">https://github.com/cobralibre/hotpotato</a> )
评论 #4763044 未加载
kmfrkover 12 years ago
Here is Paul Irish's .function dotfile solution: <a href="https://github.com/paulirish/dotfiles/blob/master/.functions#L55" rel="nofollow">https://github.com/paulirish/dotfiles/blob/master/.functions...</a>.<p>Really recommend setting up his dotfiles. After you back up your dotfiles, you can install his (which overwrites yours) just by writing<p><pre><code> git clone https://github.com/paulirish/dotfiles.git &#38;&#38; cd dotfiles &#38;&#38; ./sync.sh</code></pre>
DougBTXover 12 years ago
This is another good one for formatting / filtering json: <a href="http://stedolan.github.com/jq/" rel="nofollow">http://stedolan.github.com/jq/</a>
tedchsover 12 years ago
Here is the bash alias I have been using for CLI JSON formatting, and as a bonus, my random password generator:<p>alias jsonpp='ruby -r json -e '\''puts JSON.pretty_generate(JSON.parse(STDIN.read))'\'''<p>alias md5pass='dd if=/dev/random bs=100 count=1 2&#62;/dev/null | md5'
exhumaover 12 years ago
I've done something similar a while back. A simple "works-for-me" package. Feel free to try it out:<p><a href="https://github.com/exhuma/braindump/tree/master/jsonformat" rel="nofollow">https://github.com/exhuma/braindump/tree/master/jsonformat</a>
acdhaover 12 years ago
httpie is a nice replacement for curl which, among other things, has built-in formatting so you can get pretty JSON / XML responses without giving up your ability to do things like displaying response headers:<p><a href="https://github.com/jkbr/httpie" rel="nofollow">https://github.com/jkbr/httpie</a>
Argorakover 12 years ago
I use jazor and coderay for that:<p>gem install jazor coderay<p>curl $SOMETHING | jazor | coderay -json
wooptooover 12 years ago
Or with jsonlist in NodeJS.