How to convert json text into json object inside the msg object

I have a flow that synchronize the states of 2 instances of Home Assistants. The output of sqlite query feeds a sensor node on another Home Assistant. An example output of the msg is like:

[
  {
    "state": "1",
    "shared_attrs": "{\"entity_ids\":[\"sensor.ds918plus_drive_1_temperature\",\"sensor.ds918plus_drive_2_temperature\"],\"entities\":[\"sensor.ds918plus_drive_1_temperature = 24.0℃\",\"sensor.ds918plus_drive_2_temperature = 23.0℃\"],\"icon\":\"mdi:harddisk-remove\",\"friendly_name\":\"DS918+ Suboptimal Temperature Storage Device Count\"}"
  }
]

I would like to insert a json object for the key "entity_ids" with the value from the "entity_ids" inside the json string of "shared_attrs" and remove the "shared_attrs" key/value pair. I.e.

[
  {
    "state": "1",
    "entity_ids": [
      "sensor.ds918plus_drive_1_temperature",
      "sensor.ds918plus_drive_2_temperature"
    ]
  }
]

How can I do it?

Many thanks in advance.

Hi there,

[{"id":"e7ecd5a8bf104cfa","type":"json","z":"875a27ee3d026455","name":"","property":"payload[0].shared_attrs","action":"","pretty":false,"x":360,"y":271,"wires":[["fef1d63b6149d625"]]},{"id":"880e86e307e18dc9","type":"inject","z":"875a27ee3d026455","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"state\":\"1\",\"shared_attrs\":\"{\\\"entity_ids\\\":[\\\"sensor.ds918plus_drive_1_temperature\\\",\\\"sensor.ds918plus_drive_2_temperature\\\"],\\\"entities\\\":[\\\"sensor.ds918plus_drive_1_temperature = 24.0℃\\\",\\\"sensor.ds918plus_drive_2_temperature = 23.0℃\\\"],\\\"icon\\\":\\\"mdi:harddisk-remove\\\",\\\"friendly_name\\\":\\\"DS918+ Suboptimal Temperature Storage Device Count\\\"}\"}]","payloadType":"json","x":145,"y":215,"wires":[["e7ecd5a8bf104cfa"]]},{"id":"fef1d63b6149d625","type":"debug","z":"875a27ee3d026455","name":"debug 118","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","statusVal":"","statusType":"auto","x":568,"y":295,"wires":[]}]

this worked for me, the JSON node is configured as:

But I didn't reset the shared_attrs, the result is not quite what you wanted:

1 Like

Thanks a lot bro.

You make my day!