Link to home
Start Free TrialLog in
Avatar of bschwarting
bschwarting

asked on

Python - Format JSON data to HTML

I'm new to Python, trying to teach myself the language.  I'm using Best Buy's API to test. I'm not sure how to format the JSON data so it's readable in HTML/CSS format. Can you assist?

import requests

url = "https://api.bestbuy.com/v1/products%28customerReviewAverage%3E4%7CshippingWeight%3C50%29"

querystring = {"show":"upc,salePrice,customerReviewAverage,shippingWeight","apiKey":"XXXXXXXXXXXXXX","format":"json"}

response = requests.request("GET", url, params=querystring)

print(response.text)

Open in new window


Here is how the JSON response looks.

{"from":1,"to":10,"currentPage":1,"total":190579,"totalPages":19058,"queryTime":"0.203","totalTime":"0.230","partial":false,"canonicalUrl":"/v1/products(customerReviewAverage>4|shippingWeight<50)?show=upc,salePrice,customerReviewAverage,shippingWeight&format=json&apiKey=XXXXXXXXXXXX","products":[{"upc":"760514017023","salePrice":442.99,"customerReviewAverage":5.00,"shippingWeight":11.00},{"upc":"877929006358","salePrice":489.98,"customerReviewAverage":4.80,"shippingWeight":30.80},{"upc":"664254218934","salePrice":320.99,"customerReviewAverage":5.00,"shippingWeight":11.00},{"upc":"612934533280","salePrice":249.99,"customerReviewAverage":5.00,"shippingWeight":7.30},{"upc":"664254011221","salePrice":171.99,"customerReviewAverage":5.00,"shippingWeight":11.00},{"upc":"068888879262","salePrice":132.99,"customerReviewAverage":4.80,"shippingWeight":7.85},{"upc":"612934536229","salePrice":1062.99,"customerReviewAverage":4.70,"shippingWeight":28.50},{"upc":"093207100253","salePrice":499.98,"customerReviewAverage":4.40,"shippingWeight":35.89},{"upc":"865334000122","salePrice":202.99,"customerReviewAverage":4.20,"shippingWeight":9.99},{"upc":"865334000115","salePrice":237.99,"customerReviewAverage":4.30,"shippingWeight":9.99}]}

Open in new window

Avatar of bschwarting
bschwarting

ASKER

JSON is a little cleaner here.

{"from":1,"to":10,"currentPage":1,"total":190579,"totalPages":19058,"queryTime":"0.203","totalTime":"0.230","partial":false,"canonicalUrl":"/v1/products(onSale=true|source=\"bestbuy\"|onlineAvailability=true|dollarSavings>200|customerReviewAverage>4|shippingWeight<50)?show=upc,salePrice,customerReviewAverage,shippingWeight&format=json&apiKey=NYtTG3zOvgy0rI7bGwL6ZFeD","products":[{"upc":"760514017023","salePrice":442.99,"customerReviewAverage":5.00,"shippingWeight":11.00},{"upc":"877929006358","salePrice":489.98,"customerReviewAverage":4.80,"shippingWeight":30.80},{"upc":"664254218934","salePrice":320.99,"customerReviewAverage":5.00,"shippingWeight":11.00},{"upc":"612934533280","salePrice":249.99,"customerReviewAverage":5.00,"shippingWeight":7.30},{"upc":"664254011221","salePrice":171.99,"customerReviewAverage":5.00,"shippingWeight":11.00},{"upc":"068888879262","salePrice":132.99,"customerReviewAverage":4.80,"shippingWeight":7.85},{"upc":"612934536229","salePrice":1062.99,"customerReviewAverage":4.70,"shippingWeight":28.50},{"upc":"093207100253","salePrice":499.98,"customerReviewAverage":4.40,"shippingWeight":35.89},{"upc":"865334000122","salePrice":202.99,"customerReviewAverage":4.20,"shippingWeight":9.99},{"upc":"865334000115","salePrice":237.99,"customerReviewAverage":4.30,"shippingWeight":9.99}]}
Avatar of aikimark
aikimark, thanks!  I've experimented with this for a bit and no luck.  Where would I put ConvertFrom-Json in my scenario?
Please ignore my comment.  When I posted my comment this morning, I had Powershell on my mind, not Python.  My comment does NOT apply to your question topic.  Let me put on my Python cap and get back to you.
OK, thanks
What do you want the HTML to look like?  The "products" list might be best represented as an HTML table.

Are you using a library, such as Flask, to do your HTML rendering?
Just an HTML table. As far as the rendering, I'm looking for some help in that area.  Not sure which direction to go.
ASKER CERTIFIED SOLUTION
Avatar of bschwarting
bschwarting

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial