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?
To get JSON with Curl, you need to make an HTTP GET request and provide the Accept: application/json request header. The application/json request header is passed to the server with the curl -H command-line option and tells the server that the client is expecting JSON in response.
The procedure to hide curl progress bar is to pass the -s or --silent option to the curl command: Open the terminal application on your Linux/Unix. Type the command (pass -s option to curl to hide progress bar): $ curl -s https://your-dot-com-domain-name-here/ > /tmp/output. html.
json_pp converts between some input and output formats (one of them is JSON). This program was copied from json_xs and modified. The default input format is json and the default output format is json with pretty option.
There are things you can install... but the simplest way is to use python as its typically already installed.
curl localhost:3000/api/items/15/tools | python -m json.tool
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With