08-26-2020 02:21 PM
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?
08-27-2020 12:35 AM
@jmousavi - I think it comes as a single string . Try to use $response.split(\n").toString(). If not work share sample data.
08-27-2020 12:43 PM
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.
08-31-2020 11:23 AM
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.
09-03-2020 03:56 PM
Can you parse the JSON?
JSON.parse(‘{\n object : {\n source_1 : “website”,\n source_2: “website”\n }\n}’)