Azure Data Explorer - Reading JSON Data Using Kusto

Introduction 

 
You may have a requirement where you have data stored in a column in JSON format, and the business need is to read that column value. When it comes to JSON, there are a few ways that can help us to read this data and represent it in a meaningful and readable manner.
 
Let’s consider the below sample data from the table named demoData:
 
Azure Data Explorer - Reading JSON Data Using Kusto
 
In the above table, the last column named Description is holding the data in JSON format.
 

Using Dynamic

 
One way to extract data from the Description column is by using the dynamic literal as shown in the below query:
  1. demoData 
  2. | extend AllProperties = todynamic(Description)  
  3. | project Environment, BugId = AllProperties["Id"], AssignedTo = AllProperties["AssignedTo"]  
On execution of the above query, you will notice that all the properties of JSON are extracted in the form of new columns as shown below,
 
Azure Data Explorer - Reading JSON Data Using Kusto
 
We can further improvise the above query in terms of readability. If the column title and the JSON property are having the same name, then the JSON property can be directly accessed using dot as shown below for AssignedTo,
  1. demoData  
  2. | extend AllProperties = todynamic(Description)  
  3. | project Environment, BugId = AllProperties["Id"], AssignedTo = AllProperties.AssignedTo  
The result of the above query would also be the same as shown above.
 

Using parse_json

 
Sometimes, we do have a requirement to extract just one or two properties from the JSON column. In such a scenario, reading the entire JSON value and converting it would be an expensive operation. Here comes the parse_json to rescue us. Below is the sample query to achieve this:
  1. demoData   
  2. | extend AssignedTo = tostring(parse_json(Description)["AssignedTo"])  
  3. | project Environment, ItemId, AssignedTo  
On execution of the above query, the below result can be achieved:
 
Azure Data Explorer - Reading JSON Data Using Kusto
 
Hope you enjoyed extracting JSON data.
 
Happy Kustoing!