I am tired of logging JSON and seeing
[Array] on my terminal.
Now all you have to do is
console.log(JSON.stringify(data)) and pipe the command you run to jq. Like shown below:
node index.js | jq
Which will output this beautiful JSON ✨ that we wanted in the first place.
Sometimes the output isn't always just stringified JSON, there can also be other logs and errors in some cases. For jq to function properly it needs to ignore those logs. You can ignore it by using
node index.js | jq -R 'fromjson? | select(type == "object")'
Hope you found the article useful. Let me know your thoughts in the comments below or you can @ me on twitter