Hacker News new | ask | show | jobs
by labelbias 2177 days ago
Just recently used xq to convert and clean up a bunch of weird xml files to JSON. It was such a breeze.

I love how nested lists inside objects can expand into a particular one with the .[] operator.

For example:

{ a: [{b: 5}, {b: 3}], c: 5} can be transformed into: [{ b: 5, c: 5}, {b: 3, c: 5}] using jq '{c: .c, b: .a[].b}'

For heavily nested XMLs I can get a nice flat output.

1 comments

Nice! I've found xml transforms is one of the best applications of jq (yes, jq, not xq).

In a future post, I'll cover how to use jq not just for json and xml but any data format.