0

I have this nested json dictionary and I want to rename the key name 'Keys' with its equivalent value using Python. I wonder if this is possible?

Current - 'Keys': ['AWS Backup'] I want it to be - 'AWS Backup': ['AWS Backup']

Sample json dictionary {'TimePeriod': {'Start': '2022-11-28', 'End': '2022-11-29'}, 'Total': {}, 'Groups': [{'Keys': ['AWS Backup'], 'Metrics': {'UnblendedCost': {'Amount': '0.000000111', 'Unit': 'USD'}}}, {'Keys': ['AWS Direct Connect'], 'Metrics': {'UnblendedCost': {'Amount': '0.0000111', 'Unit': 'USD'}}}, {'Keys': ['AWS Key Management Service'], 'Metrics': {'UnblendedCost': {'Amount': '0.000000111', 'Unit': 'USD'}}}

Tried do flatten the json but after doing it still no luck. I'm not sure if I can do it using pandas dataframe also? Plan to save that json also in a csv file.

1 Answer 1

0

I think it is best if you follow the same method as the answer here, you cannot rename it, but you can copy the data to a new key and get rid of the old one

d = {'old_name': 1}
d['new_name'] = d.pop('old_name')

Python Edit/Rename Key Names in .json

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.