How to extract Json in AppInsights Analytics Query

Copper Contributor

I am using following query in AppInsights Analytics

traces
| where operation_Id == 'f3cd894d-5b92-45d4-12bd-08d5b6695afc'
| where itemType == 'trace' and timestamp > ago(24h)
| top 101 by timestamp desc
 
This gives me data. Now I would like to parse the customDimensions field to extract one value. My custom dimension data looks like

{"{OriginalFormat}":"Time taken to process validation message with operation Id - {0} is : {1} seconds","CategoryName":"WebJob.Sample","ActivityID":"f3cd894d-5b92-45d4-12bd-08d5b6695afc","0":"f3cd894d-5b92-45d4-12bd-08d5b6695afc","1":"6.2814211"}

 
I am writing a query to create an extra column and populate the time(which is in {1})
 
traces
| where operation_Id == 'f3cd894d-5b92-45d4-12bd-08d5b6695afc'
| where itemType == 'trace' and timestamp > ago(24h)
| where ((((((((* has 'Time' and * has 'taken') and * has 'to') and * has 'process') and * has 'validation') and * has 'message') and * has 'with') and * has 'operation') and * has 'Id')
| extend duration = extractjson('$.1', customDimensions)
| top 101 by timestamp desc
 
But it doesn't work... Any help will be really appreciated.
1 Reply

Hi,

This seems to be an issue of data types.

If your customDimensions field had been a String, the extractjson method you used would have worked well. For example, see this query.

However, your customDimensions field is of type dynamic, so you should instead use the parsejson method as shown here. In your case it should be:

... | extend duration = customDimensions["1"]

As for the text search, a more efficient solution would be something like this:

... | where customDimensions["{OriginalFormat}"] contains "Time taken to process validation message with operation Id"

HTH,

Noa