7/12/2023 0 Comments Curl json helperWe tell it to start a bash subshell where our grep_dep function is called with it’s args P 4 defines the concurrency, so 4 concurrent greps Let’s say we have JSON that looks like this: defines the replacement string where the dependency string will get placed Luckily, it’s really intuitive (unlike awk ?). Also like sed or awk, it basically has it’s own domain specific language (DSL) for querying JSON. Jq works similarly to sed or awk - like a filter that you pipe to and extract values from. See jq’s install help page for how to install on other environments. Jq isn’t a built-in command in any environment, so you have to install it. To me, bash is more expressive and succinct for certain tasks than node is. For most automation tasks, I like to use bash whenever possible because it’s faster and even more portable (I can share a bash script with team members that don’t have node.js installed). Why not just use node.js when you need to deal with JSON? By making JSON easy to work with in bash, jq opens up a lot of automation possibilities that otherwise required me to write something in node.js (which isn’t bad, it just takes longer generally). Jq can simplify the above bash to this: curl -s "" | jq '.value.joke' Luckily there’s a better way using a tool called jq. You have to pipe to 4 different utilities just to get to a property in the JSON response body! Bash doesn’t understand JSON out of the box, and using the typical text manipulation tools like grep, sed, or awk, gets difficult. That’s tough to read and even tougher to write. (Note: the above code was taken from, which is a great article). Perhaps you’ve seen or even written bash that looks like this: curl -s '' \
0 Comments
Leave a Reply. |