News for hackers. Stuff that matters.
Re:Jq: A lightweight and flexible command-line JSON processor by edgarbob on Sunday June 15, 2014 @08:34AM (#7895090)
Does anyone know of a similar tool for XML? In particular, it would be cool to have a useful way to run xpath, and maybe xquery, from the command line. The tools I've found have unfortunate interfaces, e.g. they won't read XML from stdin.
Re:Jq: A lightweight and flexible command-line JSON processor by gav on Sunday June 15, 2014 @09:27AM (#7895182)
Have you tried XMLStarlet[1]? It's my go-to for command line XML processing.

[1] http://xmlstar.sourceforge.net/

Re:Jq: A lightweight and flexible command-line JSON processor by unhammer on Sunday June 15, 2014 @10:01AM (#7895241)
Even with libxml's xmllint you can do some xpath stuff: http://wiki.apertium.org/wiki/Xml_grep
Re:Jq: A lightweight and flexible command-line JSON processor by jeroenjanssens on Sunday June 15, 2014 @11:37AM (#7895447)
I'd just use xml2json and then apply jq. Usually gets the job done. The benefit of that is that you only need to learn jq.

See this blog post I wrote a while ago for an example: http://jeroenjanssens.com/2013/09/19/seven-command-line-tool...

Re:Jq: A lightweight and flexible command-line JSON processor by cryptonector on Monday June 16, 2014 @02:49AM (#7897721)
Most of the JSON conversions from XML get it all wrong though. XML is not really an object (dict, hash) based meta-schema. It's an array-based meta-schema. XML->JSON conversions should look something like this:

    [ {"tag":"something", "attributes": { ... }, "nodes": [ ...] }, ... ]
with nodes being objects with one key to indicate if the node is a text node or an element, and if a text node then a value, and so on.
Re:Jq: A lightweight and flexible command-line JSON processor by cgrubb on Sunday June 15, 2014 @10:39AM (#7895308)
Re:Jq: A lightweight and flexible command-line JSON processor by A_COMPUTER on Sunday June 15, 2014 @05:20PM (#7896371)
I am not a huge fan of PHP, but you can do some useful stuff to XML using the PHP command line tool, provided you have the right libraries installed. I have run into situations where the package manager on a machine I'm using doesn't have an up to date xmlstartlet or xmllint, and have tidily gotten around this problem using PHP.
Re:Jq: A lightweight and flexible command-line JSON processor by bartc on Sunday June 15, 2014 @11:42AM (#7895463)