Parse stringifield JSON in RESTful sensor response

Dear HA community,

I am new here! First post.

I am struggling with an issue for which I can’t find answer. So thank you for your support and help in advance.

I am configuring a restful sensor. I can make use of some data returned in the response but not all: some properties of the returned object contain stringified JSON:

{
    "result": "success",
    "server_time": "2024-09-18T16:21:38Z",
    "shared_access": false,
    "public_access": false,
    "channel": {
        "channel_id": "89956",
        "field1": "Motion",
        "field2": "WiFi RSSI",
        "field3": "Movement Level",
        "field4": null,
        "field5": null,
        "field6": null,
        "field7": null,
        "field8": null,
        "field9": null,
        "field10": null,
        "field11": null,
        "field12": null,
        "field13": null,
        "field14": null,
        "field15": null,
        "public_flag": "false",
        "tags": null,
        "url": null,
        "metadata": "{\"fn_dp\":120,\"cg_data_led\":1,\"fn_sen\":200,\"fn_sen_cycle\":500,\"fn_sen_res\":10000,\"fn_sen_sta\":600,\"time_zone\":2}",
        "metadata_d": null,
        "description": null,
        "traffic_out": "670852",
        "traffic_in": "1514405",
        "status": "{\"status\":\"mac=4C:11:AE:8B:44:2C\",\"mac\":\"4C:11:AE:8B:44:2C\"}",
        "timezone": null,
        "write_key": "f2f8720d311b79f2ff46f90c82f4ef47",
        "created_at": "2024-08-29T08:31:02Z",
        "updated_at": "2024-08-29T09:44:46Z",
        "usage": "3477000",
        "last_entry_id": "17787",
        "last_entry_date": "2024-09-18T16:21:06Z",
        "product_id": "ubibot-ms1p",
        "device_id": "b9742251a2be279746a148f43792b8273dd243b8",
        "channel_icon": null,
        "last_ip": "80.201.32.174",
        "attached_at": "2024-08-29T08:31:02Z",
        "firmware": "HUM1-0.2.44",
        "full_dump": "0",
        "activated_at": "2024-08-29T08:46:33Z",
        "serial": "E231***KMS1P",
        "mac_address": "4C:11:AE:8B:44:2C",
        "full_dump_limit": "3",
        "cali": null,
        "allow_channel_fields": "10",
        "size_out": "1073741824",
        "size_storage": "209715200",
        "plan_code": "ubibot_free",
        "plan_start": "2024-08-29T08:31:02Z",
        "plan_end": null,
        "bill_start": "2024-08-29T08:31:02Z",
        "bill_end": "2024-09-28T08:31:02Z",
        "last_values": "{\"field1\":{\"value\":0,\"created_at\":\"2024-09-18T16:20:05Z\"},\"field3\":{\"value\":0,\"created_at\":\"2024-09-18T16:18:05Z\"}}",
        "vconfig": "{\"field1\":{\"h\":\"0\",\"u\":\"30\"},\"field2\":{\"h\":\"0\",\"u\":\"6\"},\"field3\":{\"h\":\"0\",\"u\":\"22\"}}",
        "vpref": "{\"fields\":[{\"key\":\"field1\",\"index\":0,\"visible\":true},{\"key\":\"field2\",\"index\":1},{\"key\":\"field3\",\"index\":2}],\"v\":3}",
    },
    "virtual_fields": []
}

I am interested in the content of the “last_values” key. How can I parse the stringified JSON in order to access the values?

Thank you very much for your help.

Laurent

Here is an example from my config. Looks like Ubibot data you have.
I have multiple ubibot devices that I do one API call for. Then I have separate template sensors for each field id that I want.

 - platform: template> 
    scan_interval: 30
    sensors:
      livingroom_temp:
        friendly_name: "Livingroom Temperature"
        value_template: '{{ (states.sensor.master_ubibot.attributes.channels[0].last_values|from_json).field1.value|float|round(2) }}'
        device_class: temperature
        unit_of_measurement: "°C"