
Then save the contents of our clipboard to a file: 1 pbpaste > feed.xmlįrom here, I want to query countries.
#Jq convert string to number install
You can install yq with brew install python-yq. For simplicity, I'll use the snippet below as our "feed" and walk you through what I did. It ships with a tool called xq that you can use for XML.īack to my task, I needed to figure out how many job postings in the feed would be dropped by the vendor. I figured there must be an equivalent for XML, right? There is, and it's a tool called yq that wraps jq and supports multiple other formats. Before we launched with the vendor, I needed to figure out how many jobs would be impacted. I found out a new vendor would not ingest jobs that didn't have a valid two digit country code. Our customer job feeds for vendors are in XML and often contain thousands of jobs. Jq is super powerful, but recently I wanted to do something like the example above, but with XML. So, to find which attribute was the culprit, I did jq '.email' | grep 'null' and replaced email with each sibling attribute until I got a null. With jq, I could query each attribute, and, if jq couldn't find it, it printed null. The amount of data was too large to inspect manually.
#Jq convert string to number code
This prints: 1 2 a recent issue, I had data like the JSON above, and, if one of the object fields were missing, the backend code threw an error. to select just the first one, for example), and from each one, select the email attribute. That jq command string tells it to look at each array element (you can also do. If I want see just emails, I can do jq '.email'. Let's say I have a list of people in JSON format: 1 [ I often find myself investigating a Sentry error and debugging an issue that requires inspecting JSON involved in the error. Things get even better when you need to query JSON.

I've found this immensely useful for quickly fixing issues in our public API documentation since our API documentation vendor requires valid JSON in our sample responses that we present readers.

If the JSON were invalid, it would tell you where it's invalid. to print it with better formatting (and colors!). What we did is pipe the output of our clipboard into jq and use the jq command.
