[Bug] fromJson not converting empty strings to null as described

We had an issue at production yesterday where the system tried to access a property inside an empty string.

Looking more closely, we discovered that the a!fromJson is not doing as it was supposed to do.


Here on the a!fromJson (21.1) documentation, we see that the property with an empty string it's converted to null

But when we execute the same code on the expressions, this comes back as an empty string, not maintaining its described functionality.

The problem is that when we try to access a property from a null value, it does not throw an error.


But when we try to access a property from a Text it throws an error and we know how problematic those are

  Discussion posts and replies are publicly visible

Parents
  • As an aside, I always recommend using the property() function when accessing a CDT or dictionary property from an object when you're not sure whether it'll actually have that property.  This allows you to sidestep even needing error messages.  If you really require a system error, you could look into using error() depending on whatever result you're returned from the property() function.

  • Agreed with Mike - it's always better to use a function that allows for null checking like property() or index(). Also one thing to keep in mind: "" is also considered null. For instance, if you try 

    "" = null
    it should return true. However, the problem is that "" is of type text, while null doesn't have a type. A text doesn't allow you to index fields out of it, while a field that is any type would allow that.

Reply
  • Agreed with Mike - it's always better to use a function that allows for null checking like property() or index(). Also one thing to keep in mind: "" is also considered null. For instance, if you try 

    "" = null
    it should return true. However, the problem is that "" is of type text, while null doesn't have a type. A text doesn't allow you to index fields out of it, while a field that is any type would allow that.

Children