News for hackers. Stuff that matters.
Re:Show HN: A command-line utility-belt for hacking JSON and... by keenerd on Friday September 07, 2012 @09:50PM (#4491944)
> Try doing THAT with any other CLI one-liner!

Challenge accepted.

    cat earthporn.json | \
    jshon -e data -e children -a -e data -e title -u | \
    sed -r 's/\<./\U&/g' | tr -d ' ' | sed 's/[^a-zA-Z].*//g`
I'll stick with Jshon for my routers and other little ARM devices.

But this utility is pretty nifty. Personally the whole select thing feels a little too magic for my taste, but when it works it looks quite compact. I'll probably be borrowing that colorizing feature tomorrow. And thanks for the link at the bottom :-)

Re:Show HN: A command-line utility-belt for hacking JSON and... by ralph on Saturday September 08, 2012 @04:34AM (#4492590)
Nice to see tr getting some use, though given the sed on either side I wonder if

    sed -r 's/\<./\U&/g; s/ +//g; s/[^a-zA-Z].*//'
would be better. Note, the last s/// doesn't need a g.
Re:Show HN: A command-line utility-belt for hacking JSON and... by petercooper on Friday September 07, 2012 @05:21PM (#4491246)
What's the ?ref=hn in the URL about? I'm intrigued if there's some way to track this sort of thing at GitHub. Or was it just to get around its two previous posts? ;-) (Not that I can blame you for that, gotta keep trying.)
Re:Show HN: A command-line utility-belt for hacking JSON and... by nivla on Friday September 07, 2012 @09:19PM (#4491897)
I might be wrong but I don't think you can access your Github repo's analytics. The only reason I can think off other than the one you mentioned is that if the link gets reposted to forums/blogs, he knows the source of it as HN.
Re:Show HN: A command-line utility-belt for hacking JSON and... by ddopson on Friday September 07, 2012 @05:11PM (#4491196)
Thanks! I put this tool together to tackle a bunch of common tasks I had - groveling through large JSON responses from webservices, using templates to generate documents based on structured config data, etc. I'm really happy that other people are finding it useful too. If you have any feature requests, post them!!!
Re:Show HN: A command-line utility-belt for hacking JSON and... by yoduh on Saturday September 08, 2012 @05:32AM (#4492655)
The author says: "Or it can form the backbone of a rich, full-powered Javascript command-line, inspired by "perl -pe", and doing for structured data what sed, awk, and grep do for text."

But... "structured data", at least in his examples (and nearly all the JSON I see on the web), is... text. Does his perl script handle binary json?

The author says: "Try doing THAT with any other CLI one-liner!"

Indeed I will, since I do not know perl. Should I learn it?

The folllowing seems to work, but I only tested it on the author's earthporn.json example

1. compile CamelCase filter called yycamel

2. compose throwaway sed oneliner to massage the text

3. pipe through unicode to ascii filter (not included)

4. pipe through yycamel

(I really do not like CamelCase, but whatever.)

   cat > camel.l << eof
   %%
   [ ][A-Za-z]  printf("%c",toupper(yytext[1]));
   eof

   flex -iCfa camel.l
   cc lex.yy.c -static -ll -o yycamel

   sed 's/\"title\": /\
   /g;' earthporn.json |sed 's/[[(]/\ 
   /g;' | sed '/^\"[a-zA-Z]/!d;s/[^a-zA-Z]/ /g;s/  */ /g' |yycamel
Re:Show HN: A command-line utility-belt for hacking JSON and... by ville on Friday September 07, 2012 @07:01PM (#4491610)
This is not related to underscore.js anyhow? People might find that name confusing.
Re:Show HN: A command-line utility-belt for hacking JSON and... by johnleppings on Saturday September 08, 2012 @07:02AM (#4492751)
Did you read the fucking article? The application began as a simple CLI for executing JS, and had underscore as its standard library. So it was a CLI for underscore. Then they made it JSON focused.
Re:Show HN: A command-line utility-belt for hacking JSON and... by RealCasually on Friday September 07, 2012 @04:36PM (#4491066)
I found this super useful:

cat data.json | underscore print --color

Gives you a well-formatted, color coded output for your JSON data. That is just one of the many things it can do.

Re:Show HN: A command-line utility-belt for hacking JSON and... by ashayh on Tuesday September 11, 2012 @06:42PM (#4508133)
$ zsh_prompt> alias clijson="ruby -e 'require \"rubygems\";require \"json\"; require \"ap\"; j = JSON.parse(STDIN.gets); ap j'"

command_that_emits_json | clijson

Re:Show HN: A command-line utility-belt for hacking JSON and... by tomjakubowski on Friday September 07, 2012 @11:22PM (#4492133)
underscore print --color < data.json

:)

Re:Show HN: A command-line utility-belt for hacking JSON and... by isaachawley on Friday September 07, 2012 @08:40PM (#4491834)
cat data.json | python -mjson.tool

Everything but the color.

Re:Show HN: A command-line utility-belt for hacking JSON and... by antihero on Friday September 07, 2012 @10:44PM (#4492061)
cat data.json | json_reformat

Seeing as lots of systems have yajl.

Re:Show HN: A command-line utility-belt for hacking JSON and... by foxwoods on Saturday September 08, 2012 @12:06AM (#4492204)
To inspect JSON in command-line, I prefer jsontool[1], it's more intuitive.

    something-generating-JSON-on-stdout | json [OPTIONS] [LOOKUPS]
[1] http://trentm.com/json/
Re:Show HN: A command-line utility-belt for hacking JSON and... by smagch on Saturday September 08, 2012 @02:10AM (#4492409)
Yeah, I use jsontool too. I always do on the terminal

    cat hoge.json | json | less
Re:Show HN: A command-line utility-belt for hacking JSON and... by ojiikun on Friday September 07, 2012 @05:11PM (#4491195)
Very nice! I've wanted something like this for as long as I've been a RecordStream (https://github.com/benbernard/RecordStream) fanatic.
Re:Show HN: A command-line utility-belt for hacking JSON and... by kanzure on Saturday September 08, 2012 @12:42AM (#4492260)
Does anyone have a javascript deobfuscation tool that will autorename variables in different scopes? I love working with javascript through the shell, but js-beautify doesn't always cut it.
Re:Show HN: A command-line utility-belt for hacking JSON and... by iopuy on Friday September 07, 2012 @06:18PM (#4491486)
The name of the tool is "underscore" in case you don't feel like clicking the link.
Re:Show HN: A command-line utility-belt for hacking JSON and... by RealCasually on Friday September 07, 2012 @06:54PM (#4491588)
Actually, its 'underscore_cli'.
Re:Show HN: A command-line utility-belt for hacking JSON and... by iopuy on Friday September 07, 2012 @07:18PM (#4491659)
Actually, its "underscore-CLI".
Re:Show HN: A command-line utility-belt for hacking JSON and... by RealCasually on Friday September 07, 2012 @07:23PM (#4491683)
Touche.