简体   繁体   中英

Split KQL array into multiple columns

I'm trying to build a dashboard in Azure Sentinel's workbook. One of the columns is a JSON Array of varying length. I'd like to split that array so that each element in the array becomes its own column, but I can't figure out a good way to do that. Basically I want this

-----------------------------------
Company | products
-----------------------------------
Apple     | [iMac, iPhone, iPad]
Microsoft | [xBox, xBox 360]
Google    | [Chromebook]
--------------------------------------

To become

-----------------------------------
Company | product_1 | product_2 | product_3
-----------------------------------
Apple | iMac        |iPhone     |iPad
Microsoft | xBox    |xBox 360   |
Google | Chromebook |           |
--------------------------------------

not highly-efficient, but here's an option:

datatable(company:string, products:dynamic)
[
    "Apple",     dynamic(['iMac', 'iPhone', 'iPad']),
    "Microsoft", dynamic(['xBox', 'xBox 360']),
    "Google",    dynamic(['Chromebook']),
]
| mv-apply with_itemindex=i products on (
    extend p = pack(strcat("product_", i+1), products)
    | summarize b = make_bag(p)
)
| evaluate bag_unpack(b)
| project-reorder company, product* asc

-->

| company   | product_1  | product_2 | product_3 |
|-----------|------------|-----------|-----------|
| Apple     | iMac       | iPhone    | iPad      |
| Microsoft | xBox       | xBox 360  |           |
| Google    | Chromebook |           |           |

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM