Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure LogAnalytics Parse JSON Array

I am ingesting some custom logs to Azure LogAnalytics. One of the columns contains nested json objects. I would like to return each nested object to a separate column value.

Was trying the mvexpand statement but have not had any luck.

customLog_CL
| extend test = parsejson(target_s)
| mvexpand test

The column data looks like below.

[ { "id": "00phb49dl40lBsasC0h7", "type": "PolicyEntity", "alternateId": "unknown", "displayName": "Default Policy", "detailEntry": "@{policyType=hello}" }, { "id": "0pri9mxp9vSc4lpiU0h7", "type": "PolicyRule", "alternateId": "00phb49dl40lBsasC0h7", "displayName": "All Users Login", "detailEntry": null } ]
like image 802
Sean Avatar asked Nov 20 '25 23:11

Sean


2 Answers

I'm in the exact same situation, so hopefully we can share the knowledge. I ended up doing something like this, if it's the correct way of doing it, or I have any bugs, I honestly can't tell you right now (still doing my data validation, so I'll update later on), but this should at least get you started.

customLog_CL
| mvexpand parsejson(target_s)
| extend Id=target_s["id"]
| extend type=target_s["type"]
| extend OtherId=target_s["alternateId"]
| project Id, type, OtherId
like image 80
Danni Juhl Avatar answered Nov 22 '25 23:11

Danni Juhl


This should work:

datatable(d:dynamic)  
[  
    dynamic(  
        [  
            { "id": "00phb49dl40lBsasC0h7", "type": "PolicyEntity", "alternateId": "unknown", "displayName": "Default Policy", "detailEntry": "@{policyType=hello}" },   
            { "id": "0pri9mxp9vSc4lpiU0h7", "type": "PolicyRule", "alternateId": "00phb49dl40lBsasC0h7", "displayName": "All Users Login", "detailEntry": "" }  
        ]  
    )  
]  
| mv-expand(d)  
| project key = tostring(d['id']), value = d
| extend p = pack(key, value)
| summarize bag = make_bag(p)
| evaluate bag_unpack(bag)

Output

like image 40
Sharoon Srivastava Avatar answered Nov 23 '25 00:11

Sharoon Srivastava



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!