使用 Excel Power Query 将 JSON 数组提取到同一行

问题描述 投票:0回答:1

我有以下 JSON

{
    "Data": {
        "totalExecutionTime": "00:00:00.5544916",
        "totalCount": "33414",
        "Items": [
            {
                "featureId": 100,
                "featureName": "Product",
                "id": 5903,
                "parentId": 0,
                "brand": "Normal",
                "order": 0,
                "createdDate": "2022-08-18T19:00:57.44",
                "modifiedDate": "2024-07-10T13:21:29.123",
                "Values": [
                    {
                        "featureId": 100,
                        "featureName": "Value",
                        "seq": 0,
                        "modifiedDate": "2022-08-18T19:03:05.84",
                        "value": "AMA83257"
                    },
                    {
                        "featureId": 281,
                        "featureName": "RetailPrice",
                        "seq": 0,
                        "modifiedDate": "2022-08-18T20:30:37.503",
                        "value": "155"
                    }
                ]
            },
            {
                "featureId": 100,
                "featureName": "Product",
                "id": 5905,
                "parentId": 0,
                "brand": "Normal",
                "order": 0,
                "createdDate": "2022-08-18T19:00:57.44",
                "modifiedDate": "2024-07-09T07:01:15.36",
                "Values": [
                    {
                        "featureId": 100,
                        "featureName": "Value",
                        "seq": 0,
                        "modifiedDate": "2022-08-18T19:03:05.84",
                        "value": "AMAXE46071"
                    },
                    {
                        "featureId": 281,
                        "featureName": "RetailPrice",
                        "seq": 0,
                        "modifiedDate": "2023-06-05T14:45:54.257",
                        "value": "245.2"
                    }
                ]
            }
        ]
    }
}

我需要以这种格式获取出色的数据

项目 价格
AMA83257 155
AMAXE46071 245.2
json excel powerquery data-cleaning m
1个回答
0
投票

enter image description here

let
    Source = Json.Document(File.Contents("C:\Users\Dav\OneDrive\Desktop\test.json")),
    Data = Source[Data],
    Items = Data[Items],
    #"Converted to Table" = Table.FromList(Items, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Added Custom" = Table.AddColumn(#"Converted to Table", "Custom", each [Column1][Values]{0}[value]),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each [Column1][Values]{1}[value]),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Column1"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Custom", "Item"}, {"Custom.1", "Price"}})
in
    #"Renamed Columns"
© www.soinside.com 2019 - 2024. All rights reserved.