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

CoderN
Thu, 05 Feb 2026 23:33:57 +0000
General

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.

4 posts - 3 participants