I am trying to format the data that is being scraped from my API. It prints in JSON format as coded. However, my question is how can I format it to make it print data like this:
Product ID: 123456789
Physical Quantity: 20
Quantity Available: 20
At the moment, it prints such as this. It asks the user to input a product ID and then goes to the API to get product information.
{
"payload": [
{
"productId": "10229480",
"quantityPhysical": 20,
"quantityAvailable": 20
}
]
}
The Python code is as follows:
import json
import requests
from colorama import Fore, Style
# getting data from source
get_data = input(Fore.LIGHTRED_EX + "Please enter a product ID to check stock level: ")
beep = requests.get("https://api.mywebsite.co.uk/shop/api/productsStock/" + get_data)
# pretty printing data
pretty_data = json.dumps(beep.json(), indent=4)
print(pretty_data)