DEV Community

Kiran (AK) Adapa
Kiran (AK) Adapa

Posted on

2 2

Get pretty json API responses using a simple Python script

If you are searching for data or documents via websites, there is a good chance that the data is presented to you using REST API behind the scenes.

Sometimes, it could get tedious if you are using a website to get the same kind of information for different identifiers/keys. If this website has an API behind the scenes then you could straight way use that API. This could be achieved from your shell/Terminal using some simple tools.

This post is about using these 'tools' on a Mac OS:

assumed a website is using REST API GET requests such as this and response from this api is coming in JSON format...

https://api.website.com/lookup/byId?id=9876def

then, you could use a simple Python script as follows to get a pretty print of the JSON response right from the terminal.

import urllib2
import json

response = urllib2.urlopen('https://api.website.com/lookup/byId?id=9876def')

data = json.load(response)
formatted_data = json.dumps(data, indent=2)

print formatted_data
Enter fullscreen mode Exit fullscreen mode

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs