# Impossible to parse simple array from SQL node

**URL:** https://discourse.nodered.org/t/impossible-to-parse-simple-array-from-sql-node/72924
**Category:** General
**Created:** [30 December 2022 00:58 UTC](https://discourse.nodered.org/t/impossible-to-parse-simple-array-from-sql-node/72924 "2022-12-30T00:58:53Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![kopter2112](https://avatars.discourse-cdn.com/v4/letter/k/dfb087/32.png) [@kopter2112](https://discourse.nodered.org/u/kopter2112)
#### Post date: [30 December 2022 00:58 UTC](https://discourse.nodered.org/t/impossible-to-parse-simple-array-from-sql-node/72924/1 "2022-12-30T00:58:53Z")

</div>

I have tried so many different ways, but as far as I understand all documentation, this should work. But it only passes "", and not the value 152 which is returned by the SQL query. This is the query I use (to get the current energy price from my price table):

`SELECT TOP 1 cast(TotalPrice as numeric(8,0)) AS TotalPrice FROM insertTableName ORDER BY Date DESC, Hour DESC`

I'm using v3.0.2 (Unraid, docker container) - Module: node-red-contrib-mssql-plus

 ![Screenshot 2022-12-30 at 01.48.39](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/9/b937fa436443a9a5e06f3b39c2b888b759a3c208.png)

---

<div class="post-metadata">

### Author: ![tve](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tve/32/59475_2.png) [@tve](https://discourse.nodered.org/u/tve)
#### Post date: [30 December 2022 01:54 UTC](https://discourse.nodered.org/t/impossible-to-parse-simple-array-from-sql-node/72924/2 "2022-12-30T01:54:06Z")

</div>

I hate mustache, it never does what I need and it's yet another language to learn. Try a change node:

```auto
[{"id":"244064707c409717","type":"inject","z":"451d9acba8e52c2f","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"TotalPrice\": 152}]","payloadType":"json","x":590,"y":140,"wires":[["ce2fbc88595972ee","d6fd584b499aae35"]]},{"id":"ce2fbc88595972ee","type":"debug","z":"451d9acba8e52c2f","name":"debug 21","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":800,"y":200,"wires":[]},{"id":"d6fd584b499aae35","type":"change","z":"451d9acba8e52c2f","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload[0].TotalPrice","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":800,"y":120,"wires":[["ce2fbc88595972ee"]]}]

```

---

<div class="post-metadata">

### Author: ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)
#### Post date: [30 December 2022 06:22 UTC](https://discourse.nodered.org/t/impossible-to-parse-simple-array-from-sql-node/72924/3 "2022-12-30T06:22:59Z")

</div>

Mustache is [really simple](https://mustache.github.io/mustache.5.html) (this was the idea), especially for someone who is dealing with vue, this should be mickey mouse stuff 😉

Then again, it will be confusing when accessing array elements directly by index within mustache, the formatting will be:

```auto
payload.0.TotalPrice

```

---

<div class="post-metadata">

### Author: ![tve](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tve/32/59475_2.png) [@tve](https://discourse.nodered.org/u/tve)
#### Post date: [30 December 2022 07:02 UTC](https://discourse.nodered.org/t/impossible-to-parse-simple-array-from-sql-node/72924/4 "2022-12-30T07:02:54Z")

</div>

LOL!  
I actually looked through the docs and searched for array. No hit. That's why I don't use that stuff: if I pull up a function node I don't need to look up any docs, I just write a 1-liner, and as a bonus I can even add a comment... 🤓

---

<div class="post-metadata">

### Author: ![kopter2112](https://avatars.discourse-cdn.com/v4/letter/k/dfb087/32.png) [@kopter2112](https://discourse.nodered.org/u/kopter2112)
#### Post date: [30 December 2022 11:11 UTC](https://discourse.nodered.org/t/impossible-to-parse-simple-array-from-sql-node/72924/5 "2022-12-30T11:11:15Z")

</div>

Thank you. I ended up using script instead figuring out the template node is not that good.

```auto
const object = msg.payload[0];
const TotalPrice = object.TotalPrice;
const formattedTotalPrice = TotalPrice.toFixed(2);
const result = {
CurrentTemperature: formattedTotalPrice
};
msg.payload = result;
return msg;

```

Edit: I'm passing the price as a temperature service for Apple Homekit to control stuff at home

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [28 February 2023 11:12 UTC](https://discourse.nodered.org/t/impossible-to-parse-simple-array-from-sql-node/72924/6 "2023-02-28T11:12:13Z")

</div>

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