0

I've got a kusto table that contains a number of columns and one column is dynamic. I'd like to expand this dynamic column to create extra columns in the result using one field as the header of the column.

Example dynamic column:

[
  {
    "code": "SenderID",
    "value": "XXXX"
  },
  {
    "code": "ReceiverID",
    "value": "YYYY"
  },
  {
    "code": "RecordNumber",
    "value": "00000012345"
  }
  {
    "code": "MachineName",
    "value": "Server1"
  }
]

I'd like to get my current columns from the table along with the expanded dynamic fields as columns like this:

result_table

I've tried using mv-expand and evaluate bag_unpack, but it just gives me multiple rows for each record (one row for every item in the json array):

transaction
| mv-expand identifier
| evaluate bag_unpack(identifier)
| where value == "00000012345"

Any ideas if it's possible to format the table in the way I like? I've been scouring different articles and haven't come across this question/answer.

Thank you!

1 Answer 1

2

Below is one option

datatable(i:int, d:dynamic)
[
  1, dynamic([
      {    "code": "SenderID",    "value": "XXXX"  },
      {    "code": "ReceiverID",    "value": "YYYY"  },
      {    "code": "RecordNumber",    "value": "00000012345"  },
      {    "code": "MachineName",    "value": "Server1"  }]), 
  2, dynamic([
      {    "code": "SenderID",    "value": "ZZZZ"  },
      {    "code": "ReceiverID",    "value": "WWWW"  },
      {    "code": "RecordNumber",    "value": "000000456789"  },
      {    "code": "MachineName",    "value": "Server2"  }])
]
| mv-apply d on (
    extend key = tostring(d.code)
    | extend value = d.value
    | summarize b = make_bag(pack(key, value))
)
| evaluate bag_unpack(b)
i MachineName ReceiverID RecordNumber SenderID
1 Server1 YYYY 00000012345 XXXX
2 Server2 WWWW 000000456789 ZZZZ
Sign up to request clarification or add additional context in comments.

1 Comment

This works, thanks! We'll look into reformatting the data on the source before ingesting.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.