How to change string text to object

This is the output of my device
""timestamp":"2022-07-04T14:37:01.848Z","type":"iBeacon","mac":"AC233FAB83BA","bleName":"","ibeaconUuid":"E2C56DB5DFFB48D2B060D0F5A71096E0","ibeaconMajor":0,"ibeaconMinor":0,"rssi":-20,"ibeaconTxPower":-59,"battery":0"

But I want to change the result to json object like this

object
timestamp: "2022-07-04T14:37:01.848Z"
type: "iBeacon"
mac: "AC233FAB83BA"
bleName: ""
ibeaconUuid: "E2C56DB5DFFB48D2B060D0F5A71096E0"
ibeaconMajor: 0
ibeaconMinor: 0
rssi: -20
ibeaconTxPower: -59
battery: 0

Any help would be greatly appreciated :slightly_smiling_face: :slightly_smiling_face:

The text is almost valid JSON, but only as a string (almost as internal quotes would need escaping) . To make it a valid JSON string that represents an object you would need to add { } to beginning and end.

You can do that at source, or as below
e.g.

[{"id":"f6332b85.359ec8","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"\"timestamp\":\"2022-07-04T14:37:01.848Z\",\"type\":\"iBeacon\",\"mac\":\"AC233FAB83BA\",\"bleName\":\"\",\"ibeaconUuid\":\"E2C56DB5DFFB48D2B060D0F5A71096E0\",\"ibeaconMajor\":0,\"ibeaconMinor\":0,\"rssi\":-20,\"ibeaconTxPower\":-59,\"battery\":0","payloadType":"str","x":210,"y":120,"wires":[["6b3b161b.beee6"]]},{"id":"6b3b161b.beee6","type":"template","z":"bf9e1e33.030598","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\n{{{payload}}}\n}","output":"json","x":380,"y":100,"wires":[["9efd2c72.cb6e88"]]},{"id":"9efd2c72.cb6e88","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":620,"y":100,"wires":[]}]

@E1cid
This is my source

So where should I edit to get valid JSON
thanks for your help

Source means the tcp device sending data.

please check my example.
copy my example.
Then in flow editor,
press ctrl i
then paste my code and press import.
You will then see a flow example in the editor.

p.s.
Images have their uses, but no good showing setting, best to export a small example of your issue and paste using </> button in your OG post.

Thanks for your advice
I am new for node-red :smile:
Your solution make it work well.

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