Tuesday, January 3, 2023

jq and XmlStarlet

jq:

jq is like sed for JSON data - you can use it to slice and filter and map and transform structured data with the same ease that sed, awk, grep and friends let you play with text.

[…]

jq can mangle the data format that you have into the one that you want with very little effort, and the program to do so is often shorter and simpler than you’d expect.

XmlStarlet:

XMLStarlet is a set of command line utilities (tools) which can be used to transform, query, validate, and edit XML documents and files using simple set of shell commands in similar way it is done for plain text files using UNIX grep, sed, awk, diff, patch, join, etc commands.

Via Helge Heß:

Handy if you have to read and modify XML files from within shell scripts in a reliable way (i.e. w/o a regex mess 🙃).

Update (2023-01-05): doekman:

Did you know there is also an xq? Not as feature rich as XmlStarlet, but I find it much more approachable (assuming you know xpath)

5 Comments RSS · Twitter · Mastodon


I use jq occassionally at work. I'm no power user but still find it super convenient. I saved off a bunch of common recipes off in a text file.
There is also yq for YAML, very similar idea.


Jonathan Huff

I'd also like to mention gron. It makes it easier to do some exploratory work with Json and Grep. If I really need to dig out some values in JSON I usually gron it, pipe that to grep for the text, and that makes it easier to tell how to carve out what I need with jq


I like dasel. It can work with XML. I mostly use it to convert XML to YAML.

https://github.com/TomWright/dasel

> Comparable to jq / yq, but supports JSON, YAML, TOML, XML and CSV with zero runtime dependencies.


I just discovered `jp`, which is like `jq` but seemingly uses a simpler query syntax.

https://github.com/jmespath/jp

Discovered via Norm Tovey-Walsh: https://so.nwalsh.com/2023/01/11-jp


While we are at it: there is this utility "jo" to create JSON on the command line. Might come in handy.

https://github.com/jpmens/jo

Leave a Comment