Getting data out of JSON

I have a really simple example of not being able to get data out of JSON.
I have been doing this for a long time but this is one is obviously too simple for me to be able to se the problem!

Everything I know and everything I have read says this should work.
I checked with jsonpathfinder.com because I couldn’t understand what I’d missed.
It tells me I’m doing it right.
(Even CoPilot tells me I’m correct soo I must be right eh? :wink:)

Can someone help please…

{% set data = {"date": "2024-11-30", "values": {"value1": 1, "value2": 2}} %}
data - {{ data }}
data.date - {{ data.date }}
data.values - {{ data.values }}
data.values.value1 - {{ data.values.value1 }}

values is the name of a built-in dictionary method so if the JSON data contains a key with the same name, reference it using bracket notation instead of dot notation.

{% set data = {"date": "2024-11-30", "values": {"value1": 1, "value2": 2}} %}
data - {{ data }}
data.date - {{ data.date }}
data.values - {{ data['values'] }}
data.values.value1 - {{ data['values']['value1'] }}

Excellent! Thank you.

1 Like