# Output new line character for Inject Node string

**URL:** <https://discourse.nodered.org/t/output-new-line-character-for-inject-node-string/28257>\
**Category:** General\
**Created:** [13 June 2020 00:02 UTC](https://discourse.nodered.org/t/output-new-line-character-for-inject-node-string/28257 "2020-06-13T00:02:08Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![namgk](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/namgk/32/4050_2.png) [@namgk](https://discourse.nodered.org/u/namgk)\
**Post date:** [13 June 2020 00:02 UTC](https://discourse.nodered.org/t/output-new-line-character-for-inject-node-string/28257/1 "2020-06-13T00:02:09Z")

</div>

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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/c/aca1b0c42fdd0d3940eb8bb84054d5a448025938.png)

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

> msg.payload.search(/\n/)

Thanks

---

<div class="post-metadata">

**Author:** ![michaelblight](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/michaelblight/32/445_2.png) [@michaelblight](https://discourse.nodered.org/u/michaelblight)\
**Post date:** [13 June 2020 01:55 UTC](https://discourse.nodered.org/t/output-new-line-character-for-inject-node-string/28257/2 "2020-06-13T01:55:51Z")

</div>

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

```auto
    "abc\ncde"

```

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

---

<div class="post-metadata">

**Author:** ![namgk](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/namgk/32/4050_2.png) [@namgk](https://discourse.nodered.org/u/namgk)\
**Post date:** [13 June 2020 02:50 UTC](https://discourse.nodered.org/t/output-new-line-character-for-inject-node-string/28257/3 "2020-06-13T02:50:07Z")

</div>

Perfect, thanks.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [13 June 2020 06:05 UTC](https://discourse.nodered.org/t/output-new-line-character-for-inject-node-string/28257/4 "2020-06-13T06:05:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![michaelblight](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/michaelblight/32/445_2.png) [@michaelblight](https://discourse.nodered.org/u/michaelblight)\
**Post date:** [13 June 2020 06:23 UTC](https://discourse.nodered.org/t/output-new-line-character-for-inject-node-string/28257/5 "2020-06-13T06:23:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [13 June 2020 09:20 UTC](https://discourse.nodered.org/t/output-new-line-character-for-inject-node-string/28257/6 "2020-06-13T09:20:17Z")

</div>

> [@michaelblight](#):
>
> True, I regularly forget that strings, numbers etc are valid JSON by themselves

I didn't know that!

> [@michaelblight](#):
>
> Perhaps I can hide behind the excuse that the JSON selection shows as {}, which dupes me every time.

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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/7/6718036c08c00d21b4288576be44d8eb7d20d82b.png)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [13 June 2020 12:45 UTC](https://discourse.nodered.org/t/output-new-line-character-for-inject-node-string/28257/7 "2020-06-13T12:45:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [13 June 2020 13:19 UTC](https://discourse.nodered.org/t/output-new-line-character-for-inject-node-string/28257/8 "2020-06-13T13:19:24Z")

</div>

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 🙂

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? 🙂

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [13 June 2020 15:34 UTC](https://discourse.nodered.org/t/output-new-line-character-for-inject-node-string/28257/9 "2020-06-13T15:34:18Z")

</div>

Well te drop drop when you select it says ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/7/27def5a6a8056f578dfdaf053cfb0b8179a65aa2.png) - 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 ?

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [12 August 2020 15:44 UTC](https://discourse.nodered.org/t/output-new-line-character-for-inject-node-string/28257/10 "2020-08-12T15:44:29Z")

</div>

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