I was working on a JSON API (for IconCMO) and realized that it'd be nice to be able to see the output of the API in my editor. In particular, I not only wanted the JSON output pretty-printed, but also wanted to highlight a few specific keys of the output, as that's what my code was focusing on.
Most editors let you execute shell commands in one way or another, and display their output. Here's the command I used (the URL is local-only) and its output:
OUTPUT=$(curl --request POST --data '{"Auth": {"Phone": "5555555555", "Username": "JoePUser", "Password": "password"}, "Request": {"Module": "payroll", "Section": "payment_method_form"} }' --header 'Content-type:application/json' --silent https://david.iconcmo.com/api/); echo $OUTPUT | jq '.payment_method_form.test'; echo $OUTPUT
{
"requestid": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"sessionid": "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"
}
{ "role": "staff", "session": "zzzzzzzzzzzzzzzzzzzzzzzzzz", "permissions": { "delete": true, "update": true, "read": true, "create": true }, "payment_method_form": { "test": { "requestid": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "sessionid": "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy" } } }
This way, I can easily see both the parts of the response I'm interested in, as well as the whole response (in case, for instance, there was a invalid JSON response).
Thanks to the spiffy jq tool to parse JSON on the command-line!