For my service integration, i have to send the request in json format.
I am converting my nested CDT into json format by using a!tojson function.
Here the issue is my service has some optional input parameters and when i am passing null for those parameters, a!tojson is converting them to "" (double quotes).
My service is not accepting the "", i should pass Null.
a!toJson( 'type!{urn:com:appian:types}_testCDT'( name: "ram", age: Null, place: "" ))
json looks like :
{
"sampleName" : "Test",
"Organization" : {
"Name" : "TestName",
"Branch" : ""
}
here Branch value should be Null instead of "".
Thanks in advance.
Discussion posts and replies are publicly visible
After a quick test I can confirm that a!toJson() sets the value to "null" if it's passed a literal null, and only to empty text ("") when empty text is passed. I'm not sure what data you're feeding it, but you might need to first consider whether the data itself is quite correct.
Hi Mike Schmitt
Thank you for the response.
I am trying to type-cast the CDT and converting to json.
All fields are having the datatype as Text in CDT.
I am getting the response like
"{"name":"ram","age":"","place":""}"(Text)
I can confirm this is how it behaves when using a typecast CDT. Have you considered using a Regular Expression to replace empty quotes in the resulting JSON string with NULL literals prior to passing it to your external service? That seems like a bit of a workaround but it might be better than continuing to spin your wheels dealing with Appian's inconsistent treatment of NULL values.
i.e. something like this:
regexreplaceall( pattern: "(:)""""", searchString: a!toJson( 'type!{urn:com:appian:types:TEST}TEST_testCdt'( id: null(), date: null(), createdBy: "", modifiedBy: null() ) ), replacementString: "$1NULL" )
I tried using the regular expression as you suggested but when i used the regular expression it seems my data type is changing from json to text and due to that my integration object is failing by saying bad request.
Well considering the Appian data type for JSON is text, i'm not sure what's happening there. Perhaps try making the literal "null" value you substitute in lower-case? I left mine upper-case for the sake of visibility, but most examples I found were lower (in case it even matters).
That is working perfectly but what makes the difference between NULL and null ?
I'm guessing it has to do with the JSON spec used by the system you're targetting - to be fair, the "null" literal was lowercase in the JSON in any examples I saw (not that I know much about it otherwise), I capitalized it here for effect - which may have been a bad idea ;-)