将 JSON 数组合并到 Kusto 中的 JSON 对象
Merge a JSON array into a JSON object in Kusto
假设我有一个这样的日志分析 table:
datatable(Computer:string, TimeGenerated:datetime, data:dynamic)
[
"comp1", datetime(2019-02-07 16:31:15), dynamic('[{prop1: 2}, {prop2: 0.8}, {prop3: 12.204532}, {prop4: 0}]'),
"comp2", datetime(2019-02-07 16:31:15), dynamic('[{prop1: 2}, {prop2: 0.8}]'),
"comp3", datetime(2019-02-07 16:31:15), dynamic('[{prop2: 0.8}, {prop3: 12.204532}, {prop4: 0}]'),
]
查询时,有没有办法将数据列中包含的json数组合并为一个对象,如下所示:
[{prop1:2}, {prop2:0.8}, {prop3:12.204532}, {prop4:0}] 变为 {prop1:2 , prop2: 0.8, prop3: 12.204532, prop4: 0}.
[{prop1: 2}, {prop2: 0.8}] 变为 {prop1: 2, prop2: 0.8}.
和 [{prop2: 0.8}, {prop3: 12.204532}, {prop4: 0}] 变成 {prop2: 0.8, prop3: 12.204532, prop4: 0}.
我不需要那个对象数组,我需要将它合并到一个对象上。
提前致谢。
mv-apply
救援
P.S.
JSON 文本键应该是合格的。
请注意我对 data
列所做的更改。
datatable(Computer:string, TimeGenerated:datetime, data:dynamic)
[
"comp1", datetime(2019-02-07 16:31:15), dynamic([{"prop1": 2}, {"prop2": 0.8}, {"prop3": 12.204532}, {"prop4": 0}]),
"comp2", datetime(2019-02-07 16:31:15), dynamic([{"prop1": 2}, {"prop2": 0.8}]),
"comp3", datetime(2019-02-07 16:31:15), dynamic([{"prop2": 0.8}, {"prop3": 12.204532}, {"prop4": 0}]),
]
| mv-apply e = data on (summarize data = make_bag(e))
+----------+----------------------+-----------------------------------------------------+
| Computer | TimeGenerated | data |
+----------+----------------------+-----------------------------------------------------+
| comp1 | 2019-02-07T16:31:15Z | {"prop1":2,"prop2":0.8,"prop3":12.204532,"prop4":0} |
| comp2 | 2019-02-07T16:31:15Z | {"prop1":2,"prop2":0.8} |
| comp3 | 2019-02-07T16:31:15Z | {"prop2":0.8,"prop3":12.204532,"prop4":0} |
+----------+----------------------+-----------------------------------------------------+
假设我有一个这样的日志分析 table:
datatable(Computer:string, TimeGenerated:datetime, data:dynamic)
[
"comp1", datetime(2019-02-07 16:31:15), dynamic('[{prop1: 2}, {prop2: 0.8}, {prop3: 12.204532}, {prop4: 0}]'),
"comp2", datetime(2019-02-07 16:31:15), dynamic('[{prop1: 2}, {prop2: 0.8}]'),
"comp3", datetime(2019-02-07 16:31:15), dynamic('[{prop2: 0.8}, {prop3: 12.204532}, {prop4: 0}]'),
]
查询时,有没有办法将数据列中包含的json数组合并为一个对象,如下所示:
[{prop1:2}, {prop2:0.8}, {prop3:12.204532}, {prop4:0}] 变为 {prop1:2 , prop2: 0.8, prop3: 12.204532, prop4: 0}.
[{prop1: 2}, {prop2: 0.8}] 变为 {prop1: 2, prop2: 0.8}.
和 [{prop2: 0.8}, {prop3: 12.204532}, {prop4: 0}] 变成 {prop2: 0.8, prop3: 12.204532, prop4: 0}.
我不需要那个对象数组,我需要将它合并到一个对象上。
提前致谢。
mv-apply
救援
P.S.
JSON 文本键应该是合格的。
请注意我对 data
列所做的更改。
datatable(Computer:string, TimeGenerated:datetime, data:dynamic)
[
"comp1", datetime(2019-02-07 16:31:15), dynamic([{"prop1": 2}, {"prop2": 0.8}, {"prop3": 12.204532}, {"prop4": 0}]),
"comp2", datetime(2019-02-07 16:31:15), dynamic([{"prop1": 2}, {"prop2": 0.8}]),
"comp3", datetime(2019-02-07 16:31:15), dynamic([{"prop2": 0.8}, {"prop3": 12.204532}, {"prop4": 0}]),
]
| mv-apply e = data on (summarize data = make_bag(e))
+----------+----------------------+-----------------------------------------------------+
| Computer | TimeGenerated | data |
+----------+----------------------+-----------------------------------------------------+
| comp1 | 2019-02-07T16:31:15Z | {"prop1":2,"prop2":0.8,"prop3":12.204532,"prop4":0} |
| comp2 | 2019-02-07T16:31:15Z | {"prop1":2,"prop2":0.8} |
| comp3 | 2019-02-07T16:31:15Z | {"prop2":0.8,"prop3":12.204532,"prop4":0} |
+----------+----------------------+-----------------------------------------------------+