Skip to content

Comment on Jshon: A command line program to parse, read and create JSON

Comments

There have been some attempts to make a line oriented XML format so that shell tools work; doing the same thing with JSON is possible too; there are a few ways to do it. Have been meaning to give it a go at some point. In my view it makes more sense than building a new set of tools, especially as the Jshon ones do not really seem to compose properly.

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

I have been using XML Starlet (http://xmlstar.sourceforge.net/) for many years in combination with Unix Shell. It is a very nice command line tool allowing to extract data from XML documents (using XPath expressions), to edit XML documents and even to convert XML to PYX format. The only problem it has so far is with big XML files as it loads them in the memory. But there is work going on to allow extract data without loading whole XML file in RAM.

> the Jshon ones do not really seem to compose properly.

Could you elaborate on that a bit?

Most of the operations do not map any json to json, so you cant pipe them. The whole design principle of the unix command line tools is that they all map lines to lines so anything is composable.

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.

Almost half* of the commands map json (stdin) to json (stdout). Extract, modify and insert all take and spit out json. Originally (when it only supported single commands) this is how you had to do everything. But that much piping is a real drag. Anyway, show me a shell json util that is more composable or at least provide a suggestion to improving it :-)

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.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.