Skip to main content
March 29, 2023
Question

a!toJson excluding null values.

  • March 29, 2023
  • 6 replies
  • 0 views

I have CDT with following fields

  • While using a!toJson , it is EXCLUDING fields which are having NULL values except fields with TEXT datatype.

Expresion: -  a!localVariables(
local!data: 'type!{urn:com:appian:types:RS}RS_dummyCDT'(id: 1, name: "abc"),
a!toJson(local!data)
)

Result:

 

Note: If I use parameter removeNullOrEmptyFields as true, it also excluding text fields which are null

a!localVariables(
local!data: 'type!{urn:com:appian:types:RS}RS_dummyCDT'(id: 1, name: "abc"),
a!toJson(
value: local!data,
removeNullOrEmptyFields: true
)
)

Result:

  • While using a!toJson_17r1, it is returning all the fields of the CDT irrespective of NULL values.

Expression: a!localVariables(
local!data: 'type!{urn:com:appian:types:RS}RS_dummyCDT'(id: 1, name: "abc"),
a!toJson_17r1(local!data )
)

Result:

I want to get the data the way we are getting result while using a!toJson_17r1. i.e. I want to get all the fields of CDT irrespective of NULL value.

Is there any way to achieve this using a!toJson?

6 replies

harshitb6843
March 30, 2023

I think they just improved the definition of the function to remove the null values. How about keep using the a!toJson_17r1 function?

March 30, 2023

I am concerned if a!toJson_17r1 get deprecated in future.

stefanhelzle0001
March 30, 2023

Handling of non-populated field in JSON is a very controversial topic. There is no real right or wrong.

Do you have any specific requirement from the API you are talking to?

I recommend to not use old versions of functions for new developments.

mikes0011
Brainy
March 30, 2023

In the documentation for a!toJson() it makes no mention of empty fields of other types being removed, particularly when "FALSE" is passed in for the "removeNullOrEmptyFields" parameter (even though that's also supposed to be the default behavior).

I'd suggest raising a support case with Appian to address this potential discrepancy.  I'd expect (if you're very lucky anyway) they might slot this in for an enhanced "evolved version" where the new one contains the behavior you're after - since just changing this behavior in the existing version could potentially break current uses of the current version.