Parsing / Converting String to Object

Hi there, really need assistance parsing / converting this output (coming from exec-node). The best I was able to achieve using a string-node is to isolate a single variable. The output is always these 6 lines.

Or I can get simplified to

image

Trying to get an object in this format. Thanks in advance!

5m
.. BUY: 6
.. SELL: 10
.. NEUTRAL: 10

15m
.. BUY: 2
.. SELL: 14
.. NEUTRAL: 10

Can you return

[{"BUY": 7, "SELL": 10, "NEUTRAL": 9},
{"BUY": 7, "SELL": 10, "NEUTRAL": 9},
{"BUY": 7, "SELL": 10, "NEUTRAL": 9}]

As that would be a valid JSON string, which could be passed through a JSON node.
Single quotes are not valid in a JSON

[edit] If not this should work on your initial output format

[{"id":"550f90e56d2a20f8","type":"inject","z":"452103ea51141731","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":3240,"wires":[["4a1e21f38e83239f"]]},{"id":"4a1e21f38e83239f","type":"template","z":"452103ea51141731","name":"simulate exec node output","field":"payload","fieldType":"msg","format":"handlebars","syntax":"plain","template":"5m {'one':'buy', 'two': 1}\n15m {'one':'buy', 'two': 1}","output":"str","x":340,"y":3240,"wires":[["3444de9788e63442"]]},{"id":"3444de9788e63442","type":"split","z":"452103ea51141731","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":210,"y":3280,"wires":[["b8538daefdd37bf3"]]},{"id":"b8538daefdd37bf3","type":"change","z":"452103ea51141731","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"'","fromt":"str","to":"\"","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":" {","fromt":"str","to":"\": {","tot":"str"},{"t":"set","p":"parts.ch","pt":"msg","to":", \"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":3280,"wires":[["881fc66a5dbb5c7e"]]},{"id":"881fc66a5dbb5c7e","type":"join","z":"452103ea51141731","name":"","mode":"auto","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":"false","timeout":"","count":"","reduceRight":false,"x":510,"y":3280,"wires":[["80e95241cd91f75a"]]},{"id":"80e95241cd91f75a","type":"template","z":"452103ea51141731","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":" {\"{{{payload}}} }","output":"json","x":640,"y":3280,"wires":[["0d17775e4e4e5987"]]},{"id":"0d17775e4e4e5987","type":"debug","z":"452103ea51141731","name":"debug 106","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":490,"y":3340,"wires":[]}]

Using the node-string I can replace the single quotes and append brackets, but still need commas.

Can you post text, so i can edit.

You need commas were i put them at end of each line, apart from last.

This is how it's coming in raw

5m {'RECOMMENDATION': 'SELL', 'BUY': 2, 'SELL': 15, 'NEUTRAL': 9}
15m {'RECOMMENDATION': 'STRONG_SELL', 'BUY': 0, 'SELL': 16, 'NEUTRAL': 10}
30m {'RECOMMENDATION': 'SELL', 'BUY': 3, 'SELL': 14, 'NEUTRAL': 9}
1h {'RECOMMENDATION': 'SELL', 'BUY': 2, 'SELL': 15, 'NEUTRAL': 9}
2h {'RECOMMENDATION': 'STRONG_SELL', 'BUY': 1, 'SELL': 16, 'NEUTRAL': 9}
4h {'RECOMMENDATION': 'SELL', 'BUY': 1, 'SELL': 15, 'NEUTRAL': 10}

This is how it's coming in raw

Question is why you get this weird output, the program producing it should be able to produce json as well, as it already partly does it.

it's calling on an external python scripts, that's how it come in, I have no control over it

Hi, just tried the flow ... getting "Unexpected end of JSON input" error

Your exec node output has a newline at end this should remove it also

[{"id":"550f90e56d2a20f8","type":"inject","z":"452103ea51141731","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":3240,"wires":[["4a1e21f38e83239f"]]},{"id":"4a1e21f38e83239f","type":"template","z":"452103ea51141731","name":"simulate exec node output","field":"payload","fieldType":"msg","format":"handlebars","syntax":"plain","template":"5m {'RECOMMENDATION': 'SELL', 'BUY': 2, 'SELL': 15, 'NEUTRAL': 9}\n15m {'RECOMMENDATION': 'STRONG_SELL', 'BUY': 0, 'SELL': 16, 'NEUTRAL': 10}\n30m {'RECOMMENDATION': 'SELL', 'BUY': 3, 'SELL': 14, 'NEUTRAL': 9}\n1h {'RECOMMENDATION': 'SELL', 'BUY': 2, 'SELL': 15, 'NEUTRAL': 9}\n2h {'RECOMMENDATION': 'STRONG_SELL', 'BUY': 1, 'SELL': 16, 'NEUTRAL': 9}\n4h {'RECOMMENDATION': 'SELL', 'BUY': 1, 'SELL': 15, 'NEUTRAL': 10}\n","output":"str","x":340,"y":3240,"wires":[["3444de9788e63442"]]},{"id":"3444de9788e63442","type":"split","z":"452103ea51141731","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":90,"y":3280,"wires":[["a3ccec3c7cdb1cf5"]]},{"id":"a3ccec3c7cdb1cf5","type":"switch","z":"452103ea51141731","name":"","property":"payload","propertyType":"msg","rules":[{"t":"neq","v":"","vt":"str"}],"checkall":"true","repair":true,"outputs":1,"x":210,"y":3280,"wires":[["b8538daefdd37bf3"]]},{"id":"b8538daefdd37bf3","type":"change","z":"452103ea51141731","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"'","fromt":"str","to":"\"","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":" {","fromt":"str","to":"\": {","tot":"str"},{"t":"set","p":"parts.ch","pt":"msg","to":", \"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":3280,"wires":[["881fc66a5dbb5c7e"]]},{"id":"881fc66a5dbb5c7e","type":"join","z":"452103ea51141731","name":"","mode":"auto","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":"false","timeout":"","count":"","reduceRight":false,"x":510,"y":3280,"wires":[["80e95241cd91f75a"]]},{"id":"80e95241cd91f75a","type":"template","z":"452103ea51141731","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":" {\"{{{payload}}} }","output":"json","x":640,"y":3280,"wires":[["0d17775e4e4e5987"]]},{"id":"0d17775e4e4e5987","type":"debug","z":"452103ea51141731","name":"debug 106","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":490,"y":3340,"wires":[]}]

Thank you so much!!