4 ms·
This post inspired me to add a similar post to my own blog. Why? Today I needed to parse some JSON at the command line and do some basic search and replaces an
by geocrasher 3y ago
This post inspired me to add a similar post to my own blog. Why?
Today I needed to parse some JSON at the command line and do some basic search and replaces and convert it all to CSV. The API call was easy enough with wget, and I was going to use JQ to parse the JSON. But after fiddling with it for 20 minutes and not having much luck, I resorted to my favorites:
Awk, sed, grep, cut. Save API call output to a couple of temp files, parse it with the aforementioned Unix staples in a for loop, And unless time than it would have taken me to properly learn JQ, I had the output and was able to ship it off to my customer.
Sometimes the best tool for the job is the tool you know, love, and trust.
- oweiler 3y agochatgpt is really good for creating the correct jq queries.
- geocrasher 3y agoIt's funny that you mention that! I was discussing it with a co-worker to see if they were any better with JQ than I was. They weren't. But then I realized I probably could have used chat GPT to do it. It really is a great tool for that kind of thing.
- ykonstant 3y agoIndeed, the greatest triumph of ChatGPT is to reduce the need to discuss with co-workers! :D
- bradknowles 3y agoTry `gron`. Great for taking JSON and converting it into something that can be grep'ed, and then if you need JSON out on the other end, you can then use `gron -u` to reverse the operation. Saved my sanity more times than I can count, and allows me to avoid the Cthonic black magic known as `jq`.
- BirAdam 3y agoAmazing tool. Thank you.
- geocrasher 3y agoI'll check it out- but the problem is portability. The script I wrote may need to run on machines that don't have anything but awk sed grep cut etc... That being said, I'll check it out on my local machine :)
- quickthrower2 3y agojq i find unintuitive. I prefer to use node repl to so this kind of stuff.
- heresie-dabord 3y agoCheers, mate! > Today I needed to parse some JSON You had some JSON blob, and you actually needed to glean something from it quickly and painlessly. To paraphrase Zawinski et al., you then found you had two problems. In this age of big data, the debate between parsable and human-readable state has been resolved. JSON is an anti-pattern that requires supplementary tooling to make any sense of it, nevermind naive readability.