cancel
Showing results for 
Search instead for 
Did you mean: 

How to write GET request content to a file with new lines instead of \n characters

jmousavi
New Contributor

I am trying to get an expression library from the Github API and save the content into a file in Snaplogic. When I get the content from the GET snap, it has \n characters and doesn’t recognize them as actual new lines. I then use the Width Formatter snap in order to get Snaplogic to recognize the \n characters as new lines. However, once I pass this into the File Writer snap, the file that was saved has no new lines, and the entire expression library is on one line.

Do you know how I can get Snaplogic to save the file with the new lines, formatted correctly?

6 REPLIES 6

Supratim
Contributor III

@jmousavi - I think it comes as a single string . Try to use $response.split(\n").toString(). If not work share sample data.

koryknick
Employee
Employee

If you are on Windows, try using \r\n in the Line Separator value of the Fixed Width Formatter. It may be that you’re trying to look at the file using a Windows-based editor and it is expecting the “carriage-return/line-feed” characters to indicate newline and it doesn’t understand the “line-feed” record terminator that is default on this snap.

jmousavi
New Contributor

I have tried both suggestions, but I am still having issues with Snaplogic recognizing new lines. Since I am making an Ultra task, I am no longer able to use the Fixed Width Formatter.

Here is an example of the content of the file I am getting from github:
{
object : {
source_1 : “website”,
source_2: “website”
}
}

After the getting the content from the Rest GET, this is what it looks like:
{\n object : {\n source_1 : “website”,\n source_2: “website”\n }\n}

I have also tried using the Json Formatter, but it still doesn’t recognize the \n as a new line, puts everything inside [ ], and also has quotes around the keys.

Can you parse the JSON?
JSON.parse(‘{\n object : {\n source_1 : “website”,\n source_2: “website”\n }\n}’)