I’m new to python. I have an JSON output nd get specific values from it. Can someone please help me to get the specific value
{"ABCDE": [{"Title": "Country Manager", "Name": "xxx yyy", "Office": "123-456-1234", "Cell": "xxx-xxx-xxxx", "Email": "[email protected]"}, {"Title": "Regional Manager", "Name": "abc redsbj", "Office": "yyy-yyy-yyyy", "Cell": "eee-eee-eeee", "Email": "[email protected]"}, {"Title": "General Manager", "Name": "Xyz whatever", "Office": "xxx-xxx-xxxx", "Cell": "xxx-xxx-xxxx", "Email": "[email protected]"}, {"Title": "General Manager - Regional", "Name": "whatever name", "Office": "www-www-wwww", "Cell": "rrr-rrr-rrrr", "Email": "[email protected]"}], "VWXYZ": [{"Title": "Country Manager", "Name": "nnn nnnnnnn", "Office": "123-123-1234", "Work Cell": NaN, "Email": [email protected]}, {"Title": "Regional Manager", "Name": "jane doe", "Office": "1234567890", "Work Cell": "1231231234", "Email": "[email protected]"}, {"Title": "General Manager", "Name": "Doe Jane", "Office": "1232343456", "Work Cell": "9098981234", "Email": "[email protected]"}]}
output expected
{‘ABCDE’:[‘General Manager’:Xyz whatever’, ‘Office’: ‘xxx-xxx-xxxx’, ‘Cell’: ‘xxx-xxx-xxxx’, ‘Email’: ‘[email protected]’], ‘VWXYZ’:[‘General Manager’:’Doe Jane’, ‘Office’: ‘1232343456’, ‘Work Cell’: ‘9098981234’, ‘Email’: ‘[email protected]’]}
with open(htmlFilePath, 'r', encoding='utf-8') as file:
siteCode = str(file_name)[:3]
tables = pd.read_html(file)
df = tables[1]
if df.columns[0] != "Title":
df.columns = df.iloc[0]
df = df[1:]
df = df.reset_index(drop=True)
atoDataDict[key] = df.to_dict("records")
jsonOutput = json.dumps(atoDataDict)
2
Answers
you might reformat you data
data = {
‘ABCDE’: {
‘General Manager’: ‘Xyz whatever’,
‘Office’: ‘xxx-xxx-xxxx’,
‘Cell’: ‘xxx-xxx-xxxx’,
‘Email’: ‘[email protected]’
},
‘VWXYZ’: {
‘General Manager’: ‘Doe Jane’,
‘Office’: ‘1232343456’,
‘Work Cell’: ‘9098981234’,
‘Email’: ‘[email protected]’
}
}
and then you can access specific value you want, for example
manager_abcde = data[‘ABCDE’][‘General Manager’]
If you correct your inputs and outputs, I believe you are looking to do something like: