[GRLUG] JSON parsing from bash

Dave Brondsema dave at brondsema.net
Wed Nov 2 12:06:15 EDT 2011


On 11/2/11 11:37 AM, Steve Romanow wrote:
> That might be a one liner with pythons json library.  Is bash-only a
> hard requirement?
> 

I'll admit I tried doing a one-liner with python this AM.  Pretty
trivial until you get to the point of flattening the nested keys into
dot notation.

echo '{"beep":1234, "foo":"bar"}' | python -c "import sys, json; print
'\n'.join(k+':'+str(v) for k,v in json.load(sys.stdin).items())"


As a .py file (instead of a one liner) it'd be more readable and easier
to make it do what you want with nested structures.


-- 
Dave Brondsema : dave at brondsema.net
http://www.brondsema.net : personal
http://www.splike.com : programming
              <><

-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.



More information about the grlug mailing list