# String to object conversion

**URL:** <https://discourse.nodered.org/t/string-to-object-conversion/53388>\
**Category:** General\
**Created:** [8 November 2021 16:08 UTC](https://discourse.nodered.org/t/string-to-object-conversion/53388 "2021-11-08T16:08:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MarcW84](https://avatars.discourse-cdn.com/v4/letter/m/d6d6ee/32.png) [@MarcW84](https://discourse.nodered.org/u/MarcW84)\
**Post date:** [8 November 2021 16:08 UTC](https://discourse.nodered.org/t/string-to-object-conversion/53388/1 "2021-11-08T16:08:28Z")

</div>

Hi there,  
I am currently struggling with updating my Node Red intergration of Loxone and IKEA Tradfri Panel.

I recently was able to get an array with brightness value and color temp out of my Loxone server but they now decided to change the output to a string:

temp(46,3840)

I need to turn this into an object like here:

{"brightness":211,"color\_temp":4700}

As I am a complete beginner to those things I would need some help on how to get the brightness and color\_temp value out of the string.

Many Thanky for your help

---

<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:** [8 November 2021 16:19 UTC](https://discourse.nodered.org/t/string-to-object-conversion/53388/2 "2021-11-08T16:19:59Z")

</div>

Here is an example using a change node and JSONata expression

first it matches the numbers  
then i loops though the matches and converts the strings to numbers. finally it takes the numbers and creates the object.

```auto
[{"id":"d72d6c96.dacd","type":"inject","z":"7f59364f045fd16d","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"temp(46,3840)","payloadType":"str","x":230,"y":580,"wires":[["a7cfb606.aecfc"]]},{"id":"a7cfb606.aecfc","type":"change","z":"7f59364f045fd16d","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"[[$match($$.payload, /\\d+/).match.$number($)]].{\"brightness\":$[0],\"color_temp\":$[1]}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":580,"wires":[["a966cb14.c37eb"]]},{"id":"a966cb14.c37eb","type":"debug","z":"7f59364f045fd16d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":640,"y":600,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![MarcW84](https://avatars.discourse-cdn.com/v4/letter/m/d6d6ee/32.png) [@MarcW84](https://discourse.nodered.org/u/MarcW84)\
**Post date:** [8 November 2021 19:44 UTC](https://discourse.nodered.org/t/string-to-object-conversion/53388/3 "2021-11-08T19:44:47Z")

</div>

Hi E1cid,  
thank your for helping out. I do not understand the code but it works. Many many thanks

---

<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:** [22 November 2021 19:45 UTC](https://discourse.nodered.org/t/string-to-object-conversion/53388/4 "2021-11-22T19:45:32Z")

</div>

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