In order to pretty print the cURL output which is in JSON format you can make use of the Python json module.
Example:
% curl -s https://randomuser.me/api/ | python3 -m json.tool
{
"results": [
{
"gender": "male",
"name": {
"title": "Mr",
"first": "Akhil",
"last": "Rai"
},
"location": {
"street": {
"number": 7324,
"name": "Coaker's Walk"
},
"city": "Thrissur",
"state": "Rajasthan",
"country": "India",
"postcode": 41746,
"coordinates": {
"latitude": "8.2937",
"longitude": "-5.5920"
},
"timezone": {
"offset": "-6:00",
"description": "Central Time (US & Canada), Mexico City"
}
} ...
![Pretty Print cURL JSON Output using Python json tool Pretty Print cURL JSON Output using Python json tool](https://code2care.org/howto/pretty-print-curl-json-output-terminal/images/Pretty Print cURL JSON Output using Python json tool.png)
This does format the JSON output but does not add color coding, for this, you can download packages from Brew such as jsonpp or jq
Example:
% brew install jq
![cURL JSON Output Pretty Printed with Colors cURL JSON Output Pretty Printed with Colors](https://code2care.org/howto/pretty-print-curl-json-output-terminal/images/cURL JSON Output Pretty Printed with Colors.png)
Facing issues? Have Questions? Post them here! I am happy to answer!
Author Info:
Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.
Follow him on: X
You can also reach out to him via e-mail: rakesh@code2care.org
More Posts related to cURL,
- cURL Option to show HTTP Response Status Code
- URL Encode cURL HTTP GET\POST Data with Examples
- Capture cURL Request Output to a File
- Fix: Curl No Match Found Error
- trurl: A new command-line tool for URL parsing and manipulation by cURL Developer
- Send JSON Data as Payload using cURL HTTP POST Request
- cURL: Show Request and Response Headers
- Get cURL command from Chrome Inspect Network HTTP URL
- Save cURL Command Output to a external file
- cURL DELETE Request with Examples
- How to URL Encode Data for a cURL Request Parameters
- cURL Example using IP (IPv4 and IPv6) address and Port
- How to convert a Postman request to cURL Command
- [fix] command not found curl
- How to Pretty Print cURL JSON Output in Terminal
- How to follow redirects in cURL Command Request
- How to pass authorization header using cURL
- cURL -x Use of HTTP Proxy Server Examples
- Downloading Google Chrome using cURL Command
- How to get cURL Command to run in verbose mode?
- List of 28 Protocols supported by cURL with Examples
- Hide cURL Outputs and Errors on Terminal
- cURL -d Option with Examples
- How to show SSL Certificate details using cURL Command
- Perform Basic Authentication using cURL with Examples
More Posts:
- Copy file from a remote server to current local directory system using SCP command - HowTos
- [Hibernate] The method buildSessionFactory() from the type Configuration is deprecated - Java
- SharePoint error cannot connect to the configuration database - SharePoint
- JSON Schema and Hyper-Schema : JSON Tutorial - Json-Tutorial
- How to fix java.net.NoRouteToHostException in Android Studio - Android-Studio
- Have you noticed MacOS Ventura About this Mac look like Mac OS X - Mac-OS-X
- Upload docx file using PHP script - PHP
- How to remove username from Mac Menu Bar? - MacOS