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
What's the actual problem here? Assuming that sometimes an attribute as a value and sometimes it doesn't then the recipient of the integration call will expect to receive messages with this attribute present, and if the value is empty that is still valid, isn't it? Are you able to elaborate on why you're trying to exclude blank attributes from your JSON message?
It's really more of a limitation of the downstream integration.
I could be doing an update on a single field of an existing entity of a downstream system with an integration. Ideally, I would just pass the single field as part of that entity's CDT JSON structure, rather than all the fields from the CDT for that given entity.
Providing a blank value for an existing field could potentially be seen by the downstream integration as a removal of the field rather than just the fact that I'm just not setting it. This is the main issue. I don't control the integration, so I am trying to handle things with Appian. If the field isn't passed at all by Appian, it is ignored by the downstream Integration.
As an alternative, one could arguably pass *everything* on the CDT instead of the single field, but that's basically providing more data than necessary, and isn't really a correct reflection of the update to the entity -- it's a single field I'm updating, any other fields I'm passing are extra noise and shouldn't really be updated *again*.
I don't think suppressing blank fields in JSON is that unusual an ask, is it?
Anyone? Bueller? Bueller?
We had to create a workaround for some behavior where toJson added a "Z" to pur date values. This is not exactly out of standard, but some JSON libraries commonly used do not support this. We made up a recursive expression which turns the CDT into a map while keeping our own date format.
Following this pattern you can decide for yourself whether to add a field to the outgoing map. This map can then be converted to JSON in the integration.
© 2023 Appian. All rights reserved.