I'm running into an issue with JSON, which I admittedly know little about:
I have UTF-8 encoded text that is formatted with line feeds and/or carriage returns that I'm packaging up in FME workbench to send it to an API for a software called Desk Alerts. The initial text is read from a text file and looks something like:
The enhanced alarm included the following information and instructions:******************************************************************************** blah blah blah blah additional blah blah info blah third line of blah blah blah******************************************************************************
Now, note there are line feeds at the end of each of those lines, typically the messages are actually quite verbose and the final message is constructed from several files, so keeping the individual lines are of high importance in some fashion.
The schema for the API is relatively simple - it looks something like this:
{"body": "@Value(Body)","title": "@Value(Subject)","templateId": 4,"skinId": 1,"isEveryone": true,"recipients": []}
...where @Value()
are dynamic variables containing text like the above mentioned text.
When I send these requests, I get the following error:
{"status": "Error","errorMessage": "Request model invalid","data": {"validationErrors": ["[queryParam] : The queryParam field is required.","[$.body] : '0x0A' is invalid within a JSON string. The string should be correctly escaped.
...which I've had enough Google success to know means "we don't like \n". But all of the recommendations I came across so far have been things like using \\n
instead of \n
to be "properly escaped".
So I used a regex search for [\n]
and replaced it with \\n
, which JSON now likes, but gives me messages that look like this:
The enhanced alarm included the following information and instructions:\n \n \n ********************************************************************************\n \n THE FIRE TROUBLE CIRCUIT AT CLINICAL CENTER B BLDG IS REPORTING A MALFUNCTION!\n \n ********************************************************************************\n 3\n \n \tTHIS INDICATES A MALFUNCTION OF THE FIRE SYSTEM\n \tMONDAY THRU FRIDAY, 8:00 TO 4:30 PM, PLEASE NOTIFY PHYSICAL PLANT\n \tMAINTENANCE DISPATCH AT 3-1760.\n \tALL OTHER TIMES, NOTIFY THE CAMPUS TELEPHONE OPERATOR.\n \n ******************************************************************************\n \n
As you may have picked up for the message, I have the same problem with tabs.
Am I doing this wrong? Any advice would be appreciated.