Convert json from mqtt to array / dictionary / list

I have a mqtt topic that is filled with nordpool proce data by php script.
simplified json:

nordpool/price/json/today [{"start":"2025-12-07 00:00:00","end":"2025-12-07 00:15:00","price":"0.01333"},{"start":"2025-12-07 00:15:00","end":"2025-12-07 00:30:00","price":"0.01273"}]

Now i’d like to convert it from that mqtt payload to nordpool_raw_data “format” to read it later with apexcharts. And for that i have made mqtt sensor that should read json and put data to attributes … but in that place I do fail …

mqtt sensor:

  - sensor:
      name: nordpool_price_today_json
      unique_id: nordpool_price_today_json
      state_topic: nordpool/price/json/today
      value_template: "x"
      json_attributes_topic: nordpool/price/json/today
      json_attributes_template: "{{ value }}"

Mostly by google come the json manipulations that want to find only one value … i’d like to have the whole thing as:

EE:
  - start: "2025-12-05T23:00:00+00:00"
    end: "2025-12-05T23:15:00+00:00"
    price: 69.53
  - start: "2025-12-05T23:15:00+00:00"
    end: "2025-12-05T23:30:00+00:00"
    price: 63.76

Any kind of hints or ideas are welcome.

Try:

json_attributes_template: "{{ {'EE': value_json}|tojson }}"

Thank you! It seems to be working :slight_smile:

Now i’m struggling to get that to work with ApexCharts as well … but it starts to “get over my head” …
I did add it as “data:” and that is correct:

data: 
- end: '2025-12-07 00:15:00'
  price: '"0.01333"'
  start: '2025-12-07 00:00:00'
- end: '2025-12-07 00:30:00'
  price: '"0.01273"'
  start: '2025-12-07 00:15:00'

But now with apexcharts i’m unable to parse it …

    data_generator: |
      return entity.attributes.data.map((start,index) => {
        return [new Date(start["start"]).getTime(), entity.attributes.data[index]["price"]];
      });

It seems i’m doing something totally wrong … but same time… what exactly.
It would be good to be able to debug it - print the array results to console but that I have no idea how to do :(.

Finally got it solved!

Found a way by googling to print the array to console as well and that proved that with data all was good … just the data in and the graph start/end times where a bit off … (small mistake)

But there was one I would say interesting discovery - values need to be ‘float’ and not string (as in mqtt message). That is because if values are not float the min and max in apexcharts are totally messed …

The final data_generator is:

    data_generator: |
      return entity.attributes.data.map((start,index) => {
        return [new Date(start["start"]).getTime(), parseFloat(entity.attributes.data[index]["price"])];
      });

And if needed to see what kind of data is pushed into array or in what format - you need to add console.log:

        console.log(parseFloat(entity.attributes.data[index]["price"]))