Разбор MultiLevel Json с использованием U-SQL
После анализа ниже JSON с использованием u-sql я хочу сохранить его в формате CSV - id, тип, имя,ppu, имя_батареи,batterid,battertype,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);