Transform data from array

How do i transform the below data from this format

[[a,b,c,d],[1,2,3,4],[10,20,30,40]]
to
[[a,1,10],[b,2,20],[c,3,30],[d,4,40]]

i have got some examples on forum for converting static data from one form to another

but, I have got this output from a mysql query and the results are dynamic coming in msg.payload

[[1672064640,1672064580,1672064520,1672064460],[969,969,969,972],[6,6,7,6]]

but I need the same data in this form

[[1672064640,969,6],[1672064580,969,6],[1672064520,969,7],[1672064460,972,6]]

I thought i had the solution when i started this topic, but now i am unable to get the same result.

@smanjunath211 I've moved your question to it's own topic (as the original topic was about barcharts & flexdash, you are more likely to get a reply if the title is more direct to the question, as more members will read it)

1 Like

I have tried chat.openai.com for this:

My first question was:

So then I tried it without nested loops:

I also asked him to write a Jsonata expression for this, but I think the Change node will explode if you enter such a long expression :wink:

And you can ask him also more specific to do it in one or another way:

A JSONata expression in a change node.

$$.payload[0]#$index.$.[
   [
       $,
       $$.payload[1][$index],
       $$.payload[2][$index] 
   ]
]
2 Likes

I have no clue how to use this in my situation. please bear with me
please help in understanding what and where should i replace. i am pasting the values i get from my mysql query below

[{"Time":1672071900,"m":0,"temp":93.6},{"Time":1672071840,"m":0,"temp":92.7},{"Time":1672071780,"m":0,"temp":93.3},{"Time":1672071720,"m":0,"temp":93.9}]

and i need this to be in this format for FlexDash input

[[1672064640,86.9,6],[1672064580,93.9,6],[1672064520,96.9,7],[1672064460,97.2,6]]

by using your previous suggestion in another thread, i am able to get upto here.
but it is not in required format.

[[1672072140,1672072080,1672072020,1672071960],[7,6,6,6],[95.7,95.4,95.1,96]]

EDIT

the following change node gives me one set of data in required format. not 4 sets,

what is the change required ?

[{"id":"1003e61f5e5b0cee","type":"change","z":"bbf5094bc59a03b8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$$.payload[0].Time.$.[\t   [\t       $,\t       $$.payload[0].m,\t       $$.payload[0].temp \t   ]\t]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":1840,"wires":[["acd36e1efad02cf0","9c0c7165cb86de68"]]}]

change node content

$$.payload[0].Time.$.[
   [
       $,
       $$.payload[0].m,
       $$.payload[0].temp 
   ]
]

results this

[[1672072980,6,98.1]]

only one set

That is not the same format as
[[a,b,c,d],[1,2,3,4],[10,20,30,40]]
one is an array of objects and the other an array of arrays.

Please be clear with your examples.
To guess on output this may work $$.payload.[$.*]

If you require more help, i will require a sample flow with the input data in a inject node and a clear example of the output.

[edit] from examples given

[{"id":"1b26608e566196d3","type":"inject","z":"da8a6ef0b3c9a5c8","name":"My SQL Query Output (rawdata)","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"Time\":1672073400,\"m\":6,\"temp\":99},{\"Time\":1672073340,\"m\":7,\"temp\":98.1},{\"Time\":1672073280,\"m\":6,\"temp\":98.7},{\"Time\":1672073220,\"m\":6,\"temp\":98.7}]","payloadType":"json","x":310,"y":600,"wires":[["95f032d857efa5ed"]]},{"id":"95f032d857efa5ed","type":"change","z":"da8a6ef0b3c9a5c8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$$.payload.[$.*]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":600,"wires":[["22e0d6e0318685cd"]]},{"id":"22e0d6e0318685cd","type":"debug","z":"da8a6ef0b3c9a5c8","name":"debug 86","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":700,"y":600,"wires":[]},{"id":"06fa988581035686","type":"inject","z":"da8a6ef0b3c9a5c8","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[[1672073400,6,99],[1672073340,7,98.1],[1672073280,6,98.7],[1672073220,6,98.7]]","payloadType":"json","x":230,"y":640,"wires":[["d2d1a9c2eae2f28a"]]},{"id":"d2d1a9c2eae2f28a","type":"debug","z":"da8a6ef0b3c9a5c8","name":"debug 87","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":600,"y":640,"wires":[]}]
4 Likes

Sorry for this confusion, i have a totally messed up flow doing so many things
please consider this.

first inject is what i get from mysql query
second inject is what i expect the change node to do.

[{"id":"1b26608e566196d3","type":"inject","z":"bbf5094bc59a03b8","name":"My SQL Query Output (rawdata)","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"Time\":1672073400,\"m\":6,\"temp\":99},{\"Time\":1672073340,\"m\":7,\"temp\":98.1},{\"Time\":1672073280,\"m\":6,\"temp\":98.7},{\"Time\":1672073220,\"m\":6,\"temp\":98.7}]","payloadType":"json","x":230,"y":1940,"wires":[["22e0d6e0318685cd"]]},{"id":"06fa988581035686","type":"inject","z":"bbf5094bc59a03b8","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[[1672073400,6,99],[1672073340,7,98.1],[1672073280,6,98.7],[1672073220,6,98.7]]","payloadType":"json","x":150,"y":1980,"wires":[["d2d1a9c2eae2f28a"]]},{"id":"22e0d6e0318685cd","type":"debug","z":"bbf5094bc59a03b8","name":"debug 86","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":520,"y":1940,"wires":[]},{"id":"d2d1a9c2eae2f28a","type":"debug","z":"bbf5094bc59a03b8","name":"debug 87","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":520,"y":1980,"wires":[]}]

Have you tried what @E1cid suggested in his last post?

1 Like

He has just edited and added the solution at the end of post. and it WORKS!

and amazingly the content of the change node is just this

$$.payload.[$.*]

image

Flexdash is taking the data happily.

3 Likes

Just check the final solution, its just one word. Amazing @E1cid and his Jsonata skills.

1 Like

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