Hi,

I have a nested structure and it is being used to send out payload data to a REST API. A requirement on this one is to remove certain characters e.g. <br>, ", \r, etc on text fields. I know we can do it via string replace but you will have do call that user function on each of the text fields.

Given this is a structure, not a JSON text, is there a way to iterate through the structure fields and apply the string replace on a single call instead of calling it in many places?

Not saying it is not doable, just finding a faster and more efficient way instead of putting the function on each of the fields in the structure.

Cheers,

JC

Hi,

What about convert your structure to JSON do the replace and convert back to the structure? You need to check the performance of this option compared with the option of changing 1 by 1.

Regards,

Marcelo

You are close to an option.

I'd still choose a transformation and validation in each field. But, if you don't need to do validations, what if you serialize to JSON, replace, and deserialize?



Solution
Solution

Thanks for the responses guys. I guess we will go for serialize to JSON and deserialize back to structure.

The bad thing though about our requirement is that we also need to remove double quotes. Now the serialize and deserialize won't work because per testing, it breaks the JSON format. :(