Skip to main content

I would like to convert a text like this:

||key = xxxxxxx||pair=btcusdt||exchange=binance||type=entry||stopLossPercentage={{plot_0}} ||exchangeAccountType=futures||leverage=2||side=long||positionSizePercentage=20||orderType=market||signalId=btclongfutures||

 

to something like this:

 

{"key":"YOU_KEY","pair":"STRATBTC","exchange":"binance","type":"entry"}

 

So would nee to add { } for beginning and end, and change = for : , remove || and put “ between each existing words

 

Is this possible?

Hi @TrendSurfers - This can be done with a JavaScript code step. You can use the code snippet below to parse that input into a readable object. The input text should be mapped to an input field called text.

const { text } = inputData;

const result = text
.split("||")
.filter((item) => !!item)
.map((item) => {
return item.split("=").map((item) => item.trim());
})
.reduce((target, current) => {
const nkey, value] = current;
targetrkey] = value;
return target;
}, {});

output = t{ result }];

Thanks, this is out of my league hehe.. i kinda understand the code a bit, but wouldnt know how to make use of it.. 

Thanks for taking the time tho. Ill see what i i can do with it


Hi @TrendSurfers ! 

Just in case you’re still working on this, I wanted to show you what this code would look like in practise. @ikbelkirasan ‘s code is spot on - you can simply copy and paste it into a “Run Javascript” Step that is part of the “Code by Zapier” App integration. Here’s what it looks like:

As you can see, we’ve set one Input Data field as “text” to match the code using “text” from the inputData Object.

 

When we test this Step, it shows us this result:

Is this what you were looking for, or were you wanting a text JSON representation? If you want text instead of the individual values, change the last line of code to this:

output = { result: JSON.stringify(result) }];

When we test the code with that modification, we get: 

I hope this helps clarify how you can use this in your Zaps!


Thanks for the assist @TimS :) Super helpful to see the additional breakdown, and with screenshots!


Hey thanks alot, cant wait to try it