# Convert Array into JSON

**URL:** https://discourse.nodered.org/t/convert-array-into-json/78599
**Category:** General
**Created:** [22 May 2023 08:29 UTC](https://discourse.nodered.org/t/convert-array-into-json/78599 "2023-05-22T08:29:59Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![allienka](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/allienka/32/79351_2.png) [@allienka](https://discourse.nodered.org/u/allienka)
#### Post date: [22 May 2023 08:29 UTC](https://discourse.nodered.org/t/convert-array-into-json/78599/1 "2023-05-22T08:29:59Z")

</div>

Hi,  
Im getting data from html page and need to convert the array into Json to get it into cloud.  
I am using the JSON node, but the result doesnt look like Json to me, also the data is not in the cloud.

Could anybody help me?

 ![Screenshot 2023-05-22 112850](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/7/e7c621e55502973d1d523fd9976bd8dadce77eaa.png)  
 ![Screenshot 2023-05-22 112856](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/1/41b67bb74c9d0f1cb6b1f4b04b69a93eaf4a02d5.png)

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [22 May 2023 08:40 UTC](https://discourse.nodered.org/t/convert-array-into-json/78599/2 "2023-05-22T08:40:25Z")

</div>

Looks like a JSON string to me, If you want a JS object then do not pass it through a JSON node.

---

<div class="post-metadata">

### Author: ![allienka](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/allienka/32/79351_2.png) [@allienka](https://discourse.nodered.org/u/allienka)
#### Post date: [22 May 2023 09:01 UTC](https://discourse.nodered.org/t/convert-array-into-json/78599/3 "2023-05-22T09:01:40Z")

</div>

thanks, trying it now with a function node, but somehow it separating into many objects, how to do the function correctly so I would get JSON like  
 ![Screenshot 2023-05-22 115714](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/4/248b2a7eeafce66119b49acbdf325c5b229aad3d.png)

 ![Screenshot 2023-05-22 115733](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/8/98c9f5819d7c9b6c5d1545301fcd8692818dcf58.png)

{  
"hour": 00:00-01:00,  
"price": 0.33,  
"hour": 00:10-02:00,  
"price": 0.39,

.....etc

}

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [22 May 2023 09:07 UTC](https://discourse.nodered.org/t/convert-array-into-json/78599/4 "2023-05-22T09:07:55Z")

</div>

This is not a valid JavaScript Object. You cannot have duplicate property names - each object can only have one `hour` and one `price`.

```auto
{
"hour": 00:00-01:00,
"price": 0.33,
"hour": 00:10-02:00,
"price": 0.39,
}

```

The Function code you have written is more correct; it creates an individual object for each `hour`/`price` pair.

But ultimately it depends on what you want to do with this data - and what format the cloud service you are using expects to receive.

---

<div class="post-metadata">

### Author: ![allienka](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/allienka/32/79351_2.png) [@allienka](https://discourse.nodered.org/u/allienka)
#### Post date: [22 May 2023 09:22 UTC](https://discourse.nodered.org/t/convert-array-into-json/78599/5 "2023-05-22T09:22:39Z")

</div>

you are right! i need to have the data in Json format to get them into the cloud.  
So probably now I can somehow split these into multiple JSONs for each time/price and send them to the cloud separately or create one JSON with different key names like Hour1, Price 1, etc..

the first option makes more sense

---

<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: [21 July 2023 09:23 UTC](https://discourse.nodered.org/t/convert-array-into-json/78599/6 "2023-07-21T09:23:00Z")

</div>

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