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

user10691876 picture user10691876 · Feb 18, 2019 · Viewed 8k times · Source

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.

Answer

Yoni picture Yoni · Feb 18, 2019

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