I have an array that comes in from a SQL Stored Procedure (my SQL team does not want to change their stored procedure) with each item repeated with a seperate cell for each category. Ideally the data should be in the form as follows:
[
{'Name':"A",'Passed':100,'Rejected':10},
{'Name':"B",'Passed':92,'Rejected':0},
]
But Instead I get my data as follows:
[
{'name':"A",'Value':100,'seriesFK':"Passed"},
{'name':"A",'Value':10,'seriesFK':"Rejected"},
{'name':"B",'Value':92,'seriesFK':"Passed"}
]
I have tried using JSONata to transform the data but I am getting really stuck.
[
$[
seriesFk ='Passed']
{'Name':name,'Passed':value},
$[seriesFk ='Rejected']
{'Name':name,'Scrapped':value},
$[seriesFk ='Target']
{'Name':name,'Target':value}
]
Attached is my flow, with the sample data from the SQL query as a function node to inject for testing:
[{"id":"228dc89e.6cb1f8","type":"debug","z":"9ae8b9db.250e78","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":767.0764427185059,"y":630.1527519226074,"wires":[]},{"id":"e53fc458.989918","type":"switch","z":"9ae8b9db.250e78","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"\t[\t$[\tseriesFk ='Passed']\t{'Name':name,'Passed':value},\t\t$[seriesFk ='Rejected']\t{'Name':name,'Scrapped':value},\t\t$[seriesFk ='Target']\t{'Name':name,'Target':value}\t]\t","vt":"jsonata"}],"checkall":"true","repair":false,"outputs":1,"x":534.0729522705078,"y":735.8437843322754,"wires":[["228dc89e.6cb1f8"]]},{"id":"fdb0c14c.a1049","type":"template","z":"9ae8b9db.250e78","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"\n [\n {\n \"dataSetPk\": 1,\n \"name\": \"Last Shift\",\n \"sort\": -1,\n \"value\": 1747,\n \"reasonFK\": 1,\n \"seriesFk\": \"Passed\"\n },\n {\n \"dataSetPk\": 1,\n \"name\": \"9 to 10\",\n \"sort\": 9,\n \"value\": 367,\n \"reasonFK\": 1,\n \"seriesFk\": \"Passed\"\n },\n {\n \"dataSetPk\": 1,\n \"name\": \"10 to 11\",\n \"sort\": 10,\n \"value\": 374,\n \"reasonFK\": 1,\n \"seriesFk\": \"Passed\"\n },\n {\n \"dataSetPk\": 1,\n \"name\": \"11 to 12\",\n \"sort\": 11,\n \"value\": 347,\n \"reasonFK\": 1,\n \"seriesFk\": \"Passed\"\n },\n {\n \"dataSetPk\": 1,\n \"name\": \"12 to 13\",\n \"sort\": 12,\n \"value\": 370,\n \"reasonFK\": 1,\n \"seriesFk\": \"Passed\"\n },\n {\n \"dataSetPk\": 1,\n \"name\": \"13 to 14\",\n \"sort\": 13,\n \"value\": 374,\n \"reasonFK\": 1,\n \"seriesFk\": \"Passed\"\n },\n {\n \"dataSetPk\": 1,\n \"name\": \"14 to 15\",\n \"sort\": 14,\n \"value\": 323,\n \"reasonFK\": 1,\n \"seriesFk\": \"Passed\"\n },\n {\n \"dataSetPk\": 1,\n \"name\": \"Last Shift\",\n \"sort\": -1,\n \"value\": 12,\n \"reasonFK\": 1,\n \"seriesFk\": \"Rejected\"\n },\n {\n \"dataSetPk\": 1,\n \"name\": \"9 to 10\",\n \"sort\": 9,\n \"value\": 1,\n \"reasonFK\": 1,\n \"seriesFk\": \"Rejected\"\n },\n {\n \"dataSetPk\": 1,\n \"name\": \"10 to 11\",\n \"sort\": 10,\n \"value\": 1,\n \"reasonFK\": 1,\n \"seriesFk\": \"Rejected\"\n },\n {\n \"dataSetPk\": 1,\n \"name\": \"11 to 12\",\n \"sort\": 11,\n \"value\": 1,\n \"reasonFK\": 1,\n \"seriesFk\": \"Rejected\"\n },\n {\n \"dataSetPk\": 1,\n \"name\": \"12 to 13\",\n \"sort\": 12,\n \"value\": 9,\n \"reasonFK\": 1,\n \"seriesFk\": \"Rejected\"\n },\n {\n \"dataSetPk\": 1,\n \"name\": \"13 to 14\",\n \"sort\": 13,\n \"value\": 1,\n \"reasonFK\": 1,\n \"seriesFk\": \"Rejected\"\n },\n {\n \"dataSetPk\": 1,\n \"name\": \"14 to 15\",\n \"sort\": 14,\n \"value\": 2,\n \"reasonFK\": 1,\n \"seriesFk\": \"Rejected\"\n },\n {\n \"dataSetPk\": 1,\n \"name\": \"Last Shift\",\n \"sort\": -1,\n \"value\": 300,\n \"reasonFK\": 1,\n \"seriesFk\": \"Target\"\n },\n {\n \"dataSetPk\": 1,\n \"name\": \"9 to 10\",\n \"sort\": 9,\n \"value\": 300,\n \"reasonFK\": 1,\n \"seriesFk\": \"Target\"\n },\n {\n \"dataSetPk\": 1,\n \"name\": \"10 to 11\",\n \"sort\": 10,\n \"value\": 300,\n \"reasonFK\": 1,\n \"seriesFk\": \"Target\"\n },\n {\n \"dataSetPk\": 1,\n \"name\": \"11 to 12\",\n \"sort\": 11,\n \"value\": 300,\n \"reasonFK\": 1,\n \"seriesFk\": \"Target\"\n },\n {\n \"dataSetPk\": 1,\n \"name\": \"12 to 13\",\n \"sort\": 12,\n \"value\": 300,\n \"reasonFK\": 1,\n \"seriesFk\": \"Target\"\n },\n {\n \"dataSetPk\": 1,\n \"name\": \"13 to 14\",\n \"sort\": 13,\n \"value\": 300,\n \"reasonFK\": 1,\n \"seriesFk\": \"Target\"\n },\n {\n \"dataSetPk\": 1,\n \"name\": \"14 to 15\",\n \"sort\": 14,\n \"value\": 300,\n \"reasonFK\": 1,\n \"seriesFk\": \"Target\"\n }\n ]","output":"json","x":271.06945037841797,"y":740.0521192550659,"wires":[["e53fc458.989918"]]},{"id":"1faa8995.2b67b6","type":"inject","z":"9ae8b9db.250e78","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":87.07638549804688,"y":734.4167022705078,"wires":[["fdb0c14c.a1049"]]}]
Anyone who could point me to model flow or additional information it would be greatly appreciated. Or I would not look a gift horse in the mouth if someone made me a flow. The help on this board is amazing so I do not want to abuse the kind souls that help so many people out.
Regards,
Jon