Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract fields from Json using Kusto in Application Insights

I have the following json contained in a particular field in the traces.customDimensions:

enter image description here

When I parse this Json to extract a particular value I always get an empty column, for example:

traces | order by timestamp desc
| project CurrentContext = parse_json(customDimensions.CurrentPluginContext)
| extend Source = CurrentContext.source
| project Source

The query returns the following:

enter image description here

I've also tried:

traces | order by timestamp desc
| project timestamp, CurrentContext = customDimensions.CurrentPluginContext, CurrentParentContext = customDimensions.CurrentParentluginContext,
Source = parse_json(tostring(customDimensions.CurrentPluginContext)).source,
DepthCurrentContext = parse_json(tostring(customDimensions.CurrentPluginContext)).depth,
DepthCurrentParentContext = parse_json(tostring(customDimensions.CurrentParentluginContext)).depth
| mv-expand CurrentContext
| extend Source = CurrentContext.source

But here I get also an empty "Source" column. And the Columns "DepthCurrentContext" and "DepthCurrentParentContext" do not even appear.

enter image description here

The Json is valid.

Do I miss something here?

Any help is very appreciated!

UPDATE 27.02.2023

When I do the following:

let json = '{"source": "GetUserData","correlationId": "00000000-0000-0000-0000-000000000000","depth": "1","initiatingUserId": "00000000-0000-0000-0000-000000000000","isInTransaction": "False","isolationMode": "2","message": "Update","mode": "Asynchronus","operationId": "00000000-0000-0000-0000-000000000000","orgId": "00000000-0000-0000-0000-000000000000","orgName": "unqXXXXXXXXXXXXXXXXXXXX","requestId": "00000000-0000-0000-0000-000000000000","userId": "00000000-0000-0000-0000-000000000000","entityId": "00000000-0000-0000-0000-000000000000","entityName": "systemuser","type": "Plugin","stage": "Post-operation"}';

traces
| extend properties = parse_json(json)
| project Source = properties.source, CorrelationID = properties.correlationId

I get the properties out of the Json. The Json is the exact same as the ohne from the log.

Any idea?

like image 542
Paul Richardson Avatar asked Mar 12 '26 14:03

Paul Richardson


1 Answers

as mentioned in the documentation: you will need to use tostring on the internal property bag.

i.e. parse_json(tostring(parse_json(customDimensions).CurrentPluginContext))

enter image description here

like image 92
Yoni L. Avatar answered Mar 16 '26 05:03

Yoni L.



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!