I would prefer to have this output in another format but I am struggling with how to get it.
CODE:
params = urllib.parse.urlencode({
})
try:
conn = http.client.HTTPSConnection('api-extern.XXX.se')
conn.request("GET", "/product/v1/product?%s" % params, "{body}", headers)
response = conn.getresponse()
data = response.read()
json_data = json.loads(data)
df = pd.io.json.json_normalize(json_data)
df.to_csv(r'C:\Users\aaa.bbb\Documents\Python Scripts\file.csv', index=False, sep=';',encoding='utf-8')
conn.close()
OUTPUT
all products for a site are merged to one cell

WANTED OUTPUT
Either:
- all products in a row and all sites as columns
- or all flat with first site 1 with all products as rows and then site 2 with all products.
Expected output alternative 1
Expected output alternative 2
The structure of the output is: [
{
"SiteId": "string",
"Products": [
{
"ProductId": "string",
"ProductNumber": "string"
}
]
}
]
Example
[{
"SiteId": "0102",
"Products": [{
"ProductId": "12107708",
"ProductNumber": "7070501"
},
{
"ProductId": "15578",
"ProductNumber": "26804"
},
{
"ProductId": "15671",
"ProductNumber": "600102"
}
]
}
]
Output from pprint(data) in Spyder is:
{'ProductId': '21831062', 'ProductNumber': '3364603'},
{'ProductId': '24432865', 'ProductNumber': '133101'},
{'ProductId': '24432978', 'ProductNumber': '1194515'},
{'ProductId': '1029420', 'ProductNumber': '198301'},
{'ProductId': '12282', 'ProductNumber': '408701'},
{'ProductId': '12946229', 'ProductNumber': '7174706'},
{'ProductId': '13278', 'ProductNumber': '42302'},
{'ProductId': '1028718', 'ProductNumber': '7536001'},
{'ProductId': '12945249', 'ProductNumber': '197404'},
{'ProductId': '16380', 'ProductNumber': '1133301'},
{'ProductId': '1866', 'ProductNumber': '257102'},
{'ProductId': '24420534', 'ProductNumber': '3422315'},
{'ProductId': '24424403', 'ProductNumber': '259301'},
{'ProductId': '10276', 'ProductNumber': '18004'},
{'ProductId': '1158212', 'ProductNumber': '689401'},
{'ProductId': '21775', 'ProductNumber': '395806'},


print(data)there, and format it is as code so we can help better.SiteIdcome from? It does not appear to be in your output ofdata