How to make JSON responses readable?

I routinely use curl -H from the bash shell to ‘talk’ to my devices and the API gave me nice pretty JSON that I could read. Lately, all the JSON appears to have been minified in the response which is probably to minimize electron costs…

Anyway is there a way to ask the API for pretty JSON?

If not, does anyone know a unix tool that will pretifyJSON on the command line? I do not want to have to create a file and then launch an app to read it (PITA)!

E.g., curl -H "$auth_token" $api/devices | pretifyJSON

Anyone have an awk method for this?

This has been asked on other forums before, particularly on StackOverflow.

Please do not use the Particle Forums as your personal google.


Here is your answer by the way:

4 Likes

a) That is rude -- this is what forums are for and I DID search this form for the answer prior to posting!
b) This is specific to these APIs because a few weeks ago they used to have whitespace in them and forgive me if I missed the release notes describing this recent change in behavior (I still do not see any release notes describing these changes).
c) The prettify question was the last option if there is not an API option.
d) Thanks for the jq reference.

2 Likes

UPDATE:

For those those of you on macOS, I found a homebrew app that works well: jsonlint

brew install jsonlint

Now with curl:

curl -H "$auth" $api/devices | jsonlint

… gives readable results.

1 Like

Nice. You were able to find something better than what I suggested. It never hurts to do some research.