Prettify Your CURL JSON Outputs - Mullin Stack
Better code – Better human
Better code – Better human

Prettify Your CURL JSON Outputs

CURL JSON responses

Today I was making CURL API requests. You do this when you need to manually make API calls.

The output of those requests might be no formatted. They look so bad on your command line. They are unreadable!.

In order to show the response in pretty way we need to do the following.

This is your CURL request.

curl 'https://maps.googleapis.com/maps/api/timezone/json?location=39.6034810,-119.6822510×tamp=1331161200&key=YOUR_API_KEY'

What you need to do is just to add the `| json_pp` at the end of the request, and your response will be prettier. Like the following

curl 'https://maps.googleapis.com/maps/api/timezone/json?location=39.6034810,-119.6822510×tamp=1331161200&key=YOUR_API_KEY'|json_pp

A prettier output

{
          {  "html_attributions" : [
               "Place name"
            ],
            "height" : 1856,
            "photo_reference" : "ATtYBwL_iOY0oTaggdeFuY11m-XyU-ktpE5SrIrIDvgebl-9EIY8ialm0Q6pAm0i9dsdd",
            "width" : 2784
         },
         {
            "width" : 800,
            "photo_reference" : "d-qCc4meQ_Zc- c69QWnETBNAt9mC7iT8r5UWuqvDMoEgGnjWEGtW0c1uygphgMYAnFPZxqA9CBVju_MTPGdu2e",
            "html_attributions" : [
               "HHHunt Homes at The Reserve at Wackena"
            ],
            "height" : 533
         }
      ],
      "utc_offset" : 400,
      "international_phone_number" : "+1 919-822-8731",
      "vicinity" : "505 Parkhurst Place, Cary"
  }

That’s all for today. I hope this turned into helpful for you. Share it to reach a wider audience who are struggling with this.

Leave a comment

Your email address will not be published.