Change "." for "," inside JSON

Hi friends, I have a really big Spreadsheet with GSheets and it’d be a pain in the but to change the decimal format of the document.

I’d like to change the json from my Shopify Webhook, so I can translate 5.00 to > 5,00. It’d make my life way much easier!

Thank you!

1 Like

Hi @Aleix_Iglesias

This is an example of how you can do that.

Please edit these value. (Since I’m replying from mobile it’s hard for me to type)

From Shopify trigger drag the arrow & create a new function node then Open it.

Now paste this code.

Make sure to edit the 3rd line path according to yours. (Replace: $node[“Set”].json[“Value”] with the item path from the Shopify trigger)

// Code here will run only once, no matter how many input items there are.
// More info and help: https://docs.n8n.io/nodes/n8n-nodes-base.function
var replace = $node["Set"].json["Value"]
// Loop over inputs and add a new field called 'myNewField' to the JSON of each one
for (item of items) {
  item.json.Replaced = replace.replace(/\./g, ',');
}

// You can write logs to the browser console
console.log('Done!');

return items;

As you can see in the above screenshot. The point has been changed to comma.

2 Likes

Wow, it worked perfectly! Thank you!

1 Like

Glad it worked. :heart: Enjoy :tada:

1 Like

Hello,

I am trying to replace a “.” with a “,” following your example but execution says “TypeError: replace.replace is not a function”.

The code is:

The workflow is:

I need to replace the “.” for a “,” in the values of tvl.

Any idea what I am doing wrong? Thanks!

1 Like

I assume that the type of that property is Number and not String. So you would first have to convert it first to a string.

Meaning the line would be:

var replace = $node['HTTP Request'].json["tvl"].toString();

actually would also make the most sense to also move the .replace up to that line and remove it from the loop.

2 Likes

Thaanks @jan it worked. Here is what I finally did:

// Loop over inputs and add a new field called 'myNewField' to the JSON of each one
for (item of items) {
  item.json.tvl = item.json.tvl.toString().replace(/\./g, ',');
}

// You can write logs to the browser console
console.log('Done!');

return items;

I needed the loop because withput it, every value was the same.

1 Like

Glad to hear that it worked. Have fun!

1 Like