gpt4 book ai didi

azure-log-analytics - 如何用kusto查询语言解析json数组

转载 作者:行者123 更新时间:2023-12-05 01:31:03 26 4
gpt4 key购买 nike

如何在 kusto 查询语言中解析 json 数组。我有一个输出列,它具有 JSON 数组格式的值,如下所示。我需要解析它以获取两列形式的值。

{"count": 14
"value": [
{
"Total_Record_Count": 16608,
"date": "2021-03-01T00:00:00Z"
},
{
"Total_Record_Count": 27254,
"date": "2021-02-24T00:00:00Z"
},
{
"Total_Record_Count": 6,
"date": "2021-02-01T00:00:00Z"
},
{
"Total_Record_Count": 26964,
"date": "2021-01-15T00:00:00Z"
},
{
"Total_Record_Count": 134516,
"date": "2020-12-18T00:00:00Z"
},
{
"Total_Record_Count": 27345,
"date": "2020-12-16T00:00:00Z"
},
{
"Total_Record_Count": 521,
"date": "2020-12-01T00:00:00Z"
},
{
"Total_Record_Count": 4,
"date": "2020-11-02T00:00:00Z"
},
{
"Total_Record_Count": 6,
"date": "2020-10-01T00:00:00Z"
},
{
"Total_Record_Count": 1,
"date": "2020-09-01T00:00:00Z"
},
{
"Total_Record_Count": 3,
"date": "2020-08-03T00:00:00Z"
},
{
"Total_Record_Count": 18,
"date": "2020-07-01T00:00:00Z"
},
{
"Total_Record_Count": 18754,
"date": "2020-06-16T00:00:00Z"
},
{
"Total_Record_Count": 4451898,
"date": "2020-06-08T00:00:00Z"
}
]}

如何使用输出列名而不是使用完整的 json 数组来实现它。

最佳答案

请参阅下面的示例,该示例使用 mv-expand 运算符将数组分解为行。 https://learn.microsoft.com/en-us/azure/data-explorer/kusto/query/mvexpandoperator

print d = dynamic(
{"count": 14,
"value": [
{
"Total_Record_Count": 16608,
"date": "2021-03-01T00:00:00Z"
},
{
"Total_Record_Count": 27254,
"date": "2021-02-24T00:00:00Z"
},
{
"Total_Record_Count": 6,
"date": "2021-02-01T00:00:00Z"
},
{
"Total_Record_Count": 26964,
"date": "2021-01-15T00:00:00Z"
},
{
"Total_Record_Count": 134516,
"date": "2020-12-18T00:00:00Z"
},
{
"Total_Record_Count": 27345,
"date": "2020-12-16T00:00:00Z"
},
{
"Total_Record_Count": 521,
"date": "2020-12-01T00:00:00Z"
},
{
"Total_Record_Count": 4,
"date": "2020-11-02T00:00:00Z"
},
{
"Total_Record_Count": 6,
"date": "2020-10-01T00:00:00Z"
},
{
"Total_Record_Count": 1,
"date": "2020-09-01T00:00:00Z"
},
{
"Total_Record_Count": 3,
"date": "2020-08-03T00:00:00Z"
},
{
"Total_Record_Count": 18,
"date": "2020-07-01T00:00:00Z"
},
{
"Total_Record_Count": 18754,
"date": "2020-06-16T00:00:00Z"
},
{
"Total_Record_Count": 4451898,
"date": "2020-06-08T00:00:00Z"
}
]})
| project Value = d.['value']
| mv-expand Value
| project Count = tolong(Value.['Total_Record_Count']), Date = todatetime(Value.['date'])
<表类="s-表"><头>计数<日>日期 <正文>44518982020-06-08 00:00:00.0000000187542020-06-16 00:00:00.0000000182020-07-01 00:00:00.000000032020-08-03 00:00:00.000000012020-09-01 00:00:00.000000062020-10-01 00:00:00.000000042020-11-02 00:00:00.00000005212020-12-01 00:00:00.0000000273452020-12-16 00:00:00.00000001345162020-12-18 00:00:00.0000000269642021-01-15 00:00:00.000000062021-02-01 00:00:00.0000000272542021-02-24 00:00:00.0000000166082021-03-01 00:00:00.0000000

关于azure-log-analytics - 如何用kusto查询语言解析json数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66564902/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com