Convert some JSON

#1

Are trying to change the output of a JSON code, but are stuck in how to do a loop for it.
I can do this with value directly - “se my ex.”

Change from

[{"Name":"name1","Number":1},{"Name":"name2","Number":2},{"Name":"name3","Number":3}]

to.

[{"name1":1},{"name2":2},{"name3":3}]

[{"id":"7efc616b.54223","type":"debug","z":"fdf95545.a593b8","name":"Output","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":790,"y":360,"wires":[]},{"id":"c97aa65f.22c208","type":"function","z":"fdf95545.a593b8","name":"","func":"var value = msg.payload[0].Name;\nvar type = msg.payload[0].Number;\n\nmsg.payload = \"{\"+value+\":\"+type+\"}\";\n\nreturn msg;\n","outputs":1,"noerr":0,"x":470,"y":360,"wires":[["7efc616b.54223"]]},{"id":"beeae646.c3bed","type":"inject","z":"fdf95545.a593b8","name":"","topic":"","payload":"[{\"Name\":\"name1\",\"Number\":1},{\"Name\":\"name2\",\"Number\":2},{\"Name\":\"name3\",\"Number\":3}]","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":360,"wires":[["c97aa65f.22c208"]]}]

0 Likes

#2

You can use a JSONata expression in a Change - very similar to the one I gave you yesterday:

$.payload.{$.Name:$.Number}
0 Likes

#3

Your the man - oh my … how easy it is when the right person shows it…

0 Likes