Need to Remove trailing \n

I have a value that I’ve extracted from JSON. Once extracted, it appears to have a trailing /n which is causing me a problem as I need to perform a select query in mysql using this value in a where clause. I’m not getting any results in my query because the value in the database is trimmed.

I’ve added a trim function, but it’s still outputting with the pesky /n and I can’t seem to get rid of it:

You can see in the query itself in the next node, that there’s a whitesapce/line break:

Any ideas? When I manually type in the value, the query works happily.

Information on your n8n setup

  • n8n version: 0.221.2
  • Database (default: SQLite): mysql hosted on aws

Here it is in JSON view - you can see the trailing whitespace is still present:

Hi @mbuk :wave: I’m not too sure without having an exact workflow / test data to work with, but you could try going the regex route and trying something like {{ $json.propertyName.replace(/[\r\n]/gm, '').trim()}} - does that work for you?

Hi @EmeraldHerald no that doesn’t appear to work.

Have a look at it here - running tests with SETs:

by adding in the regex, that appends yet another /n value:

@EmeraldHerald annoyingly, you can see in my screenshot on the input side that the value is being returned correctly, but when using this in another node (fro the output side) I can’t seem to be able to trim the whitespace.

@mbuk - can you try this?

Should be the same for your other property:


It looks like you’re seeing this because there’s still some new lines in your expression :see_no_evil:

Edit: I’d also suggest {{ $json["message"] .substring($json["message"].lastIndexOf('ShortAddr') + 12, $json["message"].lastIndexOf('ShortAddr') + 18) }}
be replaced withL
{{ JSON.parse($json.message).ZbState.ShortAddr }} :+1:

1 Like

Thank looks to have done it - thank you so much!


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