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}โ€™)