My goal is to send text to Open AI for embedding models.
I have a HTTP response object thats returned with a string including new line characters
//this shows in the input preview of current HTTP request node
[{
thestring: "Lorem ipsum dolor sit amet\nconsectetur adipiscing elit. Nunc\n
luctus risus erat, sit amet varius elit finibus\n..."
},{
thestring: "Lorem ipsum dolor sit amet\nconsectetur adipiscing elit. Nunc\n
luctus risus erat, sit amet varius elit finibus\n..."
}]
// the error in fixed view
Bad control character in string literal in JSON at position 37 (line 2 column 36)
//Inside the json configuration editor
{
"input": "{{ $json[$index]['thestring'] }}",
"model": "text-embedding-3-small",
"encoding_format": "float"
}
Expression Result output
-------------
// notice the \n are removed.
{
"input": ""Lorem ipsum dolor sit amet
consectetur adipiscing elit. Nunc
luctus risus erat, sit amet varius elit finibus
..."",
"model": "text-embedding-3-small",
"encoding_format": "float"
}
Is theres a way to keep the \n or replace the \n with " " or any other suggestion would be great
Hi @quickee, thanks for posting
It would be helpful to see how the data is passed between the nodes, could you maybe share your workflow JSON instead of the example data youâve posted above? Also, what do you mean by âjson configuration editorâ here?
You can also try using replace('\n', '\\n') to include double backslashes (\\) instead of single backslashes (\) for the newline characters. Would that help?
I did attempt string.replace(â\nâ, " "), that did not work. But I will give double backslash a try.
re: âjson configuration editor (Expression)â - there are three sections when in node editor. Left (Input) - Middle (Editor) - Right (Output). The middle section has editors for mapping âfixed, expressionâ etc.
If you switch to âfixedâ display, the JSON shows to have that error in my original post. Which is the âExpression Result outputâ
If you want to use input from previous nodes within a text, youâll have to use Expression mode instead of Fixed.
Which nodes are you using? A screenshot or sharing your workflow json by selecting the relevant nodes and pasting in the json between ``` here would be great to understand whatâs going!
Davidâs right, since {{ $json[$index][âthestringâ] }} is already a string, removing the double quotes around it in the input field should help! Try it out and let us know how it goes.