I am trying to do this:
curl localhost:3000/api/items/15/tools
This is the return right now:
{"recipe_tools":[{"id":19,"name":"Cutting Board","prices":{"display":"49ドル.99","value":"49.99"},"description":"Built to last,
... (and then like a million lines)
And it keeps going...
How do I pretty print or awesome print this? What can I do?
4 Answers 4
There are things you can install, but the simplest way is to use Python as it's typically already installed.
curl localhost:3000/api/items/15/tools | python -m json.tool
Comments
I use jq to pretty-print it.
jq
is a lightweight and flexible command-line JSON processor.
jq
is written in portable C, and it has zero runtime dependencies.
E.g.
Without JSON formatter
$ curl -s http://localhost:3000; echo
{"account":{"id":"HXRC","uri":["mailto:[email protected]","tel:366-643-7219"],"features":["585"],"nickname":"Consultant"}}
Install jq
(Ubuntu):
$ sudo apt-get install jq
Use jq
json formatter.
$ curl -s http://localhost:3000 | jq '.'
{
"account": {
"id": "HXRC",
"uri": [
"mailto:[email protected]",
"tel:366-643-7219"
],
"features": [
"585"
],
"nickname": "Consultant"
}
}
You can find more examples in tutorial. You can find the installation for each OS in download page
1 Comment
jq
is also available through Homebrew, so brew install jq
Port 3000 makes me think you are using Rails.
I have used JSON.pretty_generate(json_obj)
on my RoR applications to have a JSON object return properly indented.
curl
? You can't; it doesn't. There are plenty of tools you could pipe some JSON into and format it though. As such, I would suggest this is actually a software recommendation request.