使用U-SQL解析MultiLevel Json

时间:2018-12-04 08:49:19

标签: u-sql

使用u-sql在JSON下解析后,我想将其保存为CSV- id,类型,名称,ppu,电池名称,电池,电池类型,toppingDate,toppingid,toppingtype。

我的代码在id到ppu字段之间都有效,但不超出该范围。

Json样本- { "id": "0001", "type": "donut", "name": "Cake", "ppu": 0.55, "batters": {"battername":"NA", "batter": { { "batterid": "1001", "battertype": "Regular" }, { "batterid": "1002", "battertype": "Chocolate" }, { "batterid": "1003", "battertype": "Blueberry" }, { "batterid": "1004", "battertype": "Devil's Food" } } }, "topping": [{ "toppingDate": "2018-11-30T10:00:01", "toppingValues": [ { "toppingid": "5001", "toppingtype": "None" }, { "toppingid": "5002", "toppingtype": "Glazed" }, { "toppingid": "5005", "toppingtype": "Sugar" }, { "toppingid": "5007", "toppingtype": "Powdered Sugar" }, { "toppingid": "5006", "toppingtype": "Chocolate with" }, { "toppingid": "5003", "toppingtype": "Chocolate" }, { "toppingid": "5004", "toppingtype": "Maple" } ]} }

REFERENCE ASSEMBLY [Newtonsoft.Json];
REFERENCE ASSEMBLY [Microsoft.Analytics.Samples.Formats];
USING Microsoft.Analytics.Samples.Formats.Json;
DECLARE EXTERNAL @InputPath string = @"input.json"; 
DECLARE EXTERNAL @OutputPath string = @"output.csv";
@commonCookedInput =
EXTRACT id string,
        type string,
        name string,
        ppu int?,
        battername string,
        batterid int?,
        battertype string
FROM @InputPath
USING new MultiLevelJsonExtractor( "batters.id",
                                   "batters.type",
                                   "batters.name",
                                   "batters.ppu",
                                   "batters.battername",
                                   "batters.batterid", 
                                   "batters.battertype"
                                  );
OUTPUT @commonCookedInput
TO @OutputPath
USING Outputters.Csv(quoting: false,outputHeader:true);

0 个答案:

没有答案