I am still new to Python and I am still trying a lot of new things in this aspect. I am working with an API that contains JSON data that looks as follow:
products: [
{
id: 66057248,
createdAt: "2018-02-28T14:55:22+01:00",
updatedAt: "2018-04-26T20:44:12+02:00",
isVisible: true,
visibility: "visible",
hasMatrix: false,
data01: "",
data02: "",
data03: "",
url: "product-name",
title: "product name",
fulltitle: "product name",
etc...
What I am trying to do now is to let the user give input on the values in the JSON file that he wants to compare with each other. I tried a couple of things but so far without a result. I am probably doing something stupid, but I don't know what.
As you can see in my code below, I ask the user two times for the input, and these values are the values that I want to add to the for loop below. My question now is, what am I doing wrong and how can I insert the input data in the for
loop?
import requests
import json
response = requests.get('http://inserturlhere.com')
data =response.text
parsed=json.loads(data)
first_value = input ('Name of first value: ')
second_value = input ('Name of second value: ')
first_test = ['first_value']
second_test = ['second_value']
for product in parsed['products']:
if product[first_test] == product[second_test] :
print(product['id'])
requests.get('APIURL')
won't run, and we don't know whatparse['orders']
refers to.parsed['orders']
? [can you print an example] The first and only timeorders
comes up is in the 3rd last line.