Output new line character for Inject Node string

Hi there,

I have a dummy inject node that output a string. How can I make it output a new line character?

Something like this, but this doesn't work.

image

By not working I mean this in a function node returns -1:

msg.payload.search(/\n/)

Thanks

One option would be to use a change node setting the payload to the following JSONata (quotes included):

    "abc\ncde"

The inject node doesn't have the option of JSONata, hence the use of the change node.

Perfect, thanks.

It can send Json. So you can so the same trick with the inject node.

True, I regularly forget that strings, numbers etc are valid JSON by themselves - it doesn't have to be an object. Perhaps I can hide behind the excuse that the JSON selection shows as {}, which dupes me every time.

I didn't know that!

That does confuse me as I don't use it that often - I always debate whether I should stick a { before and } after my JSON text

I'd much prefer it didn't show them and then I would always think I should include them myself

Alternatively, if the default field entry was {} , then that would stop my confusion
image

Most often JSON is used to represent an object, for example {"a": 0} in which case you need the braces. However a simple value such as 0 or "some string" on its own is also valid json and in that case must not have the braces.

So maybe just use word JSON and miss off the { } altogether?

Would eliminate confusion for simple people - we'd just get it wrong to start with and then learn :slight_smile:

Whereas as the moment, I use it once in while and every-time I think - do I need to add in the {} or does Node-RED wrap them round for me? :slight_smile:

Well te drop drop when you select it says image - and we shorten that to just the icon which we chose to be {} so that you have the most space for the input box. You can always click the dropdown again for a reminder ?

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.