Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pretty json output from curl?

Tags:

curl

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?

like image 840
Jwan622 Avatar asked May 05 '16 20:05

Jwan622


People also ask

How do I get JSON with Curl?

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.

How do I hide my Curl output?

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.

What is Json_pp?

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.


2 Answers

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

like image 52
Grimnoff Avatar answered Sep 28 '22 01:09

Grimnoff


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.

like image 25
Isaac Meals Avatar answered Sep 28 '22 03:09

Isaac Meals