【问题标题】:Is it possible to rename a json key name using its value in Python?是否可以使用 Python 中的值重命名 json 键名?
【发布时间】:2022-12-02 17:47:38
【问题描述】:

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.

    标签: python json pandas dataframe nested-json


    【解决方案1】:
    猜你喜欢
    • 2012-06-01
    • 2018-09-21
    • 2012-08-30
    • 1970-01-01
    • 1970-01-01
    • 2013-02-22
    • 2020-07-04
    • 1970-01-01
    • 2023-04-10
    相关资源
    最近更新 更多