Skip to main content

Hi all,

i’m building an FME desktop workspace for eventual use with a server automation. we’re taking some emails, parsing them for some specific data, reading text files with additional information, and then putting it all together to be sent out via an API for a software called Desk Alerts.

Where i am running into issues is - the text files are UTF-8 encoded and contain line feeds and tabs that the API isn’t happy with.

so for instance i might have a message that looks like:
 

now you can see i’ve got 4 tabs and almost 20 line feeds.

this text is actually the combined result of several files and the content is variable so for readability’s sake maintaining the line feeds (and preferably the tabs) is paramount.

When sending to the API, i get the following error response:
 

{"status":"Error","errorMessage":"Request model invalid","data":
{"validationErrors":t"oqueryParam] : The queryParam field is required.","r$.body]
: '0x0A' is invalid within a JSON string. The string should be correctly escaped.

which if i am understanding it correctly is essentially “we don’t like those line feeds. escape them correctly!

so in my workspace i put in a string replacer, since it appears that the proper escape needs 2 slashes:

 

however, while this satisfies the API, instead of including a new line, it just includes \n where the line feeds used to be.

The enhanced alarm included the following information and instructions:\n\n \n********************************************************************************\n \n

 

I'm not sure how to approach this while maintaining individual lines.

i’d appreciate any insight.

Easiest way I find to do replacements like this is copy the ‘character’ directly from the source text. In your case, this is the first screenshot you posted.

One thing to note, is that there are probably some no width characters in there. For example, the line This indicates a malfunction of the system place the cursor just after the ‘m’ in system and select from there (using shift+right arrow) to the arrow on the next line, then move back one (shift + left arrow) and copy that and use it as the text to replace value (doesn’t need to be regex in this case).

Assuming you don’t have any other no width characters after the other line feed this should work


I found that copying the character still gets rejected by the API, but the api also supports html, so i did a replace with <b> and tabs replaced with 5 blank spaces, which it took. 

i think this is mainly a limitation of that particular API vs an issue with FME’s processing.


Reply