Question

Convert text

  • 25 July 2020
  • 2 replies
  • 95 views

Userlevel 1

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?


2 replies

Userlevel 7
Badge +8

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 [key, value] = current;
target[key] = value;
return target;
}, {});

output = [{ result }];
Userlevel 1

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

Reply