Would like be able to run a!toJson on a CDT where blank fields are suppressed

Hi,

I'm using some CDTs to generate JSON to an Integration, and would like to *not* have JSON attributes where a Text field is blank.  By default, all the attributes for my CDT are generated in the JSON string when I run the CDT through a!toJson.

Is there any way I can call a!toJson to optionally suppress blank attributes?  Or, has someone written a hack that applies this kind of "filter" after the jsonString has been generated?

I see C# and Java solutions for this kind of thing, but not sure how to do this in Appian.  Is there a plugin, something on AppMarket, etc.?

Thanks for any help!

  Discussion posts and replies are publicly visible

  • I was thinking I would have to do something to the jsonString after the CDT conversion to JSON, which is I think what you're suggesting here?

  • Sounds like the real solution is to fix the way the APIs are designed and implemented! 

    It has just occurred to me (although you'll almost certainly not like it - I know I don't!) that you could generate a full-fat JSON based upon your CDT (so it contains all of the attributes you might ever need to send in your JSON message), and then implement a post-processing rule that treats the JSON as a string (which it is!) and excise the attribute(s) you don't want sent based upon whatever are the rules e.g. if a given attribute is null and that is going to cause the API to delete the current value, then simply edit the string and remove that attribute. I'm sure if you experimented with a mixture of the text functions (find, mid, search, substitute etc.) you could implement a deterministic method of extracting the empty values and splicing the message back together so that it is still valid JSON.

    (Yuck! I know, right? But it is an option...you'd need to know the rules about what's valid at each API and perform the necessary manipulation as required...)

  • Yeah, my situation pretty much sucks.  And yeah, some kind of post-processing on the JSON String is probably the best thing I can do within Appian.

    I'm still gathering info as to how the rules even work -- I don't know that the downstream system even has that information for me.  Ugh.

    I am going to mark "Verify Answer" on your reply, but I'm not happy about it! Slight smile

  • If anything revolutionary occurs to me I'll let you know...but I feel your pain!