How to transform a JSON array of objects to a Kusto table?

戏子无情 提交于 2019-12-25 00:51:25

问题


I have a JSON schema that I get from the server and I need to transform this JSON into a log analytics query language table and use that table to make a join with another table.

The JSON has the following schema:

[{
   "X": "xyz",
   "Y": "xyz",
   "Z": "xyz",
   "prop1": "value1",
   "prop2": "value2",
   "prop3": "value3"
}, {
     "X": "xyz",
     "Y": "xyz",
     "Z": "xyz",
     "prop1": "value1",
     "prop2": "value2",
     "prop3": "value3"
}]

I tried this :

let table = todynamic('[{
  "X": "xyz",
  "Y": "xyz",
  "Z": "xyz",
  "prop1": "value1",
  "prop2": "value2", 
  "prop3": "value3"
}, {
  "X": "xyz",
  "Y": "xyz",
  "Z": "xyz",
  "prop1": "value1",
  "prop2": "value2",
  "prop3": "value3"
]');

But this does not convert the JSON into something that can be used in a join with other tables.

Any help will be very appreciated.


回答1:


try using print and dynamic:

print myDynamicValue = dynamic([{
   "X": "xyz",
   "Y": "xyz",
   "Z": "xyz",
   "prop1": "value1",
   "prop2": "value2",
   "prop3": "value3"
}, {
   "X": "xyz",
   "Y": "xyz",
   "Z": "xyz",
   "prop1": "value1",
   "prop2": "value2",
   "prop3": "value3"
}])
| mvexpand myDynamicValue // this line is just an example

Update (based on question in comments):

let result = 
print myDynamicValue = dynamic(
[
    { "X": "xyz", "Y": "xyz", "Z": "xyz", "prop1": "value1", "prop2": "value2", "prop3": "value3" }, 
    { "X": "xyz", "Y": "xyz", "Z": "xyz", "prop1": "value1", "prop2": "value2", "prop3": "value3" }
]) 
| mvexpand myDynamicValue 
| evaluate bag_unpack(myDynamicValue);
result


来源:https://stackoverflow.com/questions/54746111/how-to-transform-a-json-array-of-objects-to-a-kusto-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!