import json

data = {"products":[{"id":1,"title":"iPhone 9","description":"An apple mobile which is nothing like apple","price":549,"discountPercentage":12.96,"rating":4.69,"stock":94,"brand":"Apple","category":"smartphones","thumbnail":"https://[Log in to view URL]","images":["https://[Log in to view URL]","https://[Log in to view URL]","https://[Log in to view URL]","https://[Log in to view URL]","https://[Log in to view URL]"]},{"id":2,"title":"iPhone X","description":"SIM-Free, Model A19211 6.5-inch Super Retina HD display with OLED technology A12 Bionic chip with ...","price":899,"discountPercentage":17.94,"rating":4.44,"stock":34,"brand":"Apple","category":"smartphones","thumbnail":"https://[Log in to view URL]","images":["https://[Log in to view URL]","https://[Log in to view URL]","https://[Log in to view URL]","https://[Log in to view URL]"]},{"id":3,"title":"Samsung Universe 9","description":"Samsung's new variant which goes beyond Galaxy to the Universe","price":1249,"discountPercentage":15.46,"rating":4.09,"stock":36,"brand":"Samsung","category":"smartphones","thumbnail":"https://[Log in to view URL]","images":["https://[Log in to view URL]"]},{"id":4,"title":"OPPOF19","description":"OPPO F19 is officially announced on April 2021.","price":280,"discountPercentage":17.91,"rating":4.3,"stock":123,"brand":"OPPO","category":"smartphones","thumbnail":"https://[Log in to view URL]","images":["https://[Log in to view URL]","https://[Log in to view URL]","https://[Log in to view URL]","https://[Log in to view URL]","https://[Log in to view URL]"]},{"id":5,"title":"Huawei P30","description":"Huawei’s re-badged P30 Pro New Edition was officially unveiled yesterday in Germany and now the device has made its way to the UK.","price":499,"discountPercentage":10.58,"rating":4.09,"stock":32,"brand":"Huawei","category":"smartphones","thumbnail":"https://[Log in to view URL]","images":["https://[Log in to view URL]","https://[Log in to view URL]","https://[Log in to view URL]"]}],"total":100,"skip":0,"limit":5}

# lets get only data we want out of this data
# get the first product and the id
first_product_id = data['products'][0]['id']

# types matter, we have to change the id which is a number to string
# then we can combine them into a sentence
print("first product id: " + str(first_product_id))


# Now we do have a lot of data we don't really need.
# Let's preparer some useful data

useful_data = []

# find the id of products that are in stock and comparing the price and current discount
# loop through all the products in the data
for i in data['products']:
    
    # create a new object and populate with only the data we want
    sale_products = {}
    sale_products['id'] = i['id']
    sale_products['price'] = i['price']
    sale_products['discountPercentage'] = i['discountPercentage']
    sale_products['stock'] = i['stock']
    
    # add the data to a list for later
    useful_data.append(sale_products)

# loo at the data
print(useful_data)

# now that we have only the data we want
# we could now compare the prices and discounts to share as an insight
    

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: