Python Json格式化

时间:2018-07-16 08:40:09

标签: python json parsing

这是我的json输出,如何从下面的json中仅提取名称和状态。 过去几天,我为此感到头疼。

我需要使用for循环来获得这个?

{
    "recipes": {
        "47635": {
            "name": "Desitnation Search",
            "status": "SUCCESSFUL",
            "kitchen": "eu",
            "active": "YES",
            "created_at": 1501672231,
            "interval": 5,
            "use_legacy_notifications": false
        },
        "65568": {
            "name": "Validation",
            "status": "SUCCESSFUL",
            "kitchen": "us-west",
            "active": "YES",
            "created_at": 1522583593,
            "interval": 5,
            "use_legacy_notifications": false
        },
        "47437": {
            "name": "Gateday",
            "status": "SUCCESSFUL",
            "kitchen": "us-west",
            "active": "YES",
            "created_at": 1501411588,
            "interval": 10,
            "use_legacy_notifications": false
        }
    },
    "counts": {
        "total": 3,
        "limited": 3,
        "filtered": 3
    }
}

1 个答案:

答案 0 :(得分:-2)

是的,在这里使用for循环。

extracted_recipes = []
for recipe in d['recipes']:
    extracted_recipes.append(recipe['name'],recipe['status'])

这将为您提供元组列表。

print(extracted_recipes)
[('Desitnation Search',"SUCCESSFUL"),("Validation","SUCCESSFUL"),("Gateday","SUCCESSFUL")]