Special Characters Messing up my JSON

0
Hi, so I am trying to create a JSON and send it to an API, it works most of the time, but with a specific key that I'm updating it throws an error before calling the API. It seems as if it might be a special character that is messing it up. Any idea what the special characters in mendix are, and how best to keep them in the string but not have it mess up the JSON.. (such as a back slash or whatever). Thank you!
asked
3 answers
1

Hi Kylee,

 

if possible can you share sample JSON here.

 

Thanks,

Mobin

answered
1

For a generic solution, either use an export mapping to build your json, or if you need to build it manually, escape the value for the title (and possible other string attributes as well) first. Maybe the escapeHtml action does the job, but I have a little java action for it that takes an InputString string parameter and returns it escaped:

 

[...]
import org.apache.commons.text.StringEscapeUtils;
[...]
    // BEGIN USER CODE
    return StringEscapeUtils.escapeJson(InputString);
    // END USER CODE
[...]

 

answered
0

Hi Kylee,

 

Use escape characters while preparing your request.

Check StringUtils java actions from CommunityCommons module, you can use java actions like EscapeHTML etc.

otherwise you can write one Custom java action to implement Escape characters for your String Body.

 

Regards,

Ajay

answered