Decoding a record with variable field names

Let’s say I’m querying an endpoint that provides data across a given date range. The date range is calculated as today minus 3 days. So I know the date range in advance, but it is still dynamic in that it will change every day.

So say today is 2019-08-03, then my date range will be ["2019-08-03", "2019-08-02", "2019-01-01"].

And the response will include this:

entities: {
    2019-08-03: {...},
    2019-08-02: {...},
    2019-01-01: {...}
} 

How would I decode this exactly? Given that the field names for entities are not static, but will change will each day

1 Like

You can use Json.Decode.dict or Json.Decode.keyValuePairs

2 Likes

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.