Adventures with Event Grid: Where Did My Null Properties Go?

The other day I noticed when assigning an object to the Data property of an Event Grid Schema message ✉️, any properties, on that object, that had a null value were going to be ignored.

I thought my eyes 👀 were failing me! To test this, I wrote the following in LINQPad.

For my Person object I am setting NickName to null.

I created a simple Logic App, just composed of an HTTP Trigger, and made it a subscriber to my Event Grid topic.

I fired 🔥 off an Event Grid message ✉️ and inspected the Logic App to see what it received.

Needless to say, I was surprised 😲 to see that my nick_name property had been dropped.

Just to be sure it wasn’t localized to the Logic App, I created another subscriber to the Event Grid topic that wrote the message ✉️ to a Storage Queue.

I fired 🔥 off another Event Grid message ✉️ and inspected my Storage Queue to see what it received.

Again, my nick_name property had been dropped!

Hmmm…

Now what’s interesting, is if I do the same thing, but send the message ✉️ to Azure Queue Storage, in include the null property, probably because I am using Newtonsoft.Json to serialize the Event Grid message ✉️.

So maybe this is Event Grid specific? Not 100% 💯sure.

When supplying the sample JSON schema for my Logic App’s Parse JSON step, I had to make sure to include ALL my properties. Normally, I just pick off the JSON generated by the incoming Event Grid message ✉️ and just use that, but as I mentioned, it was dropping my null properties.

Once I did that, all was well.

In closing, not saying this is a problem, just something that was unexpected.

Were I to use an Azure Function to read the Event Grid message ✉️, and then inside the Azure Function, convert the Data property to a dynamic object, I would be missing any object properties set to null.

Just something to be aware of, hopefully save a fellow developer a head scratch or two.


Discover more from Matt Ruma

Subscribe to get the latest posts sent to your email.

Leave a Reply

Your email address will not be published. Required fields are marked *