Forum Discussion

Michael1145's avatar
Michael1145
Copper Contributor
Sep 05, 2019

parse_json() not working correctly. Returning string

I have a custom query that I have written to produce a report on specific events. My query goes as follows:

customEvents
| where todatetime(timestamp) > ago(1d)
| where customDimensions.EventType == "DEBUG"
| where customDimensions.Detail == "[Compare-Events-CalendarToUpdate][UPDATE]"
| extend events = parse_json(tostring(customDimensions.custom_object))
| project Id=events.Id,
          Detail=customDimensions.Detail,
          Owner=events.Owner, 
          Subject=events.Subject,
          Room=events.Room,
          StartDate=events.StartDate,
          EndDate=events.EndDate

 

When executing the query I am getting blank columns. Upon further investigation, I have found that extended column "events" is a type string and not an object suggesting that parse_json is not working. This is a rather large object (Approx. 21KB, however I have shrunk it and it is still having issues.) Is there a size limitation to what Kusto can read/store and deseralize?

 

Many Thanks,

 

Michael.

 

5 Replies

    • Michael1145's avatar
      Michael1145
      Copper Contributor

      Stanislav_Zhelyazkov 

       

      Please find the attached JSON sample snippet (This was serialized from PowerShell)

       

      https://gist.github.com/ZanattaMichael/bb4c7c9d5be435bd10b6f7c7b7fc5ea3

       

      The object is quite complex, so later tonight I will try and build some sample data using let.

       

      Thanks for your help!

       

      Michael.

       

       

       

      • Michael1145's avatar
        Michael1145
        Copper Contributor

        I have found a few issues:

        1. parse_json does not deal with serialized PowerShell dates. I have corrected this by double escaping the dates. I tested it by running a parse_json("JSON") within the query window.

        2. I noticed that the JSON is incomplete within the window. However testing within the browser the full json string works, so it's not a limitation of parse_json, but might be an issue with storage and retention.

        3. parse_json will return a json string and won't throw an error when passing a string. For example:

        customEvents
        | extend events = parse_json("hello world") will return "hello world"
         
        Cheers,
         
        Michael.

Resources