Jshon: A command line program to parse, read and create JSON
kmkeen.com
kmkeen.com
Using JSON to extend command line processing looks to me like it is a nice step forward. Things like Microsoft's PowerShell are perhaps conceptually more elegant (where you pass real live objects about) but the practical reality always seems very fussy and tied to a particular programming platform. Other approaches (e.g. passing XML between Unix-style command line programs) isn't very appealing due to the general ugliness and verbosity of most XML.
$ type json
json is aliased to `python -m json.tool'
$ curl -s twitter.com/users/BarackObama.json|json|grep '"url"'
"url": "http://www.barackobama.com",References for XML: http://www.lbreyer.com/unix_xml-1.html http://www.ofb.net/~egnor/xml2/ http://gnosis.cx/publish/programming/xml_matters_17.html
Could you elaborate on that a bit?
So for json I would want a structure match corresponding to grep, filter and map operations, merges etc each of which maps valid json to valid json.
Grep/filter/map are all stuff you do in the shell, after using Jshon to extract the data from the hard-to-parse-safely json.
*The remaining commands are concessions to make line-oriented shell processing easier.
echo "{ 'a': {'b': {'c": 0 } } }" | json-tool "a.b.c" # echos 0
Maybe your tool does that but I missed itYou can do similar with -e a -e b -e c. Or just make your own wrapper with
jshon $(echo ".a.b.c" | sed 's/./ -e/g')
Senator, I know awk, and that is not an alarming bit of awk.
echo '{"a": "hello", "b": "world"}' | python -c"import sys,json;j = json.loads(sys.stdin.read());print j['a']" echo '{"a": "hello", "b": "world"}' | python -mjson.tool