RedditPP Mascot

RedditPP

r/tasker • … • u/wfaulk

Loop through JSON array

I have a variable `%json` that contains a JSON structure that looks something like this:

``` { "response": { "data": { "values": [ { "title": "foo1", "author": "bar1", "text": "baz1" }, { "title": "foo2", "author": "bar2", "text": "baz2" }, { "title": "foo3", "author": "bar3", "text": "baz3" }, { "title": "foo4", "author": "bar4", "text": "baz4" } ] } } } ```

I want a For loop (or equivalent) that loops through the array at `response.data.values`, but I can't figure out how to do it.

`%json.response.data.values` contains just the JSON array, as expected, but using that as the "items" in a For Action just sees it as a single string.

Actually, I just now figured out that a Tasker-defined array `%arr()` with values `1,2,3,4` doesn't work as the "items" in a For Action either. It just goes through a single iteration with the value `1,2,3,4`. So maybe my first mistake is trying to use the For Action. (Maybe the intention is to just use it to count through array indexes?)

Regardless, I still can't get Tasker to interpret my JSON as an array. `%json.response.data.values()` is an empty string, so I can't use any array operators like `(#)`.

I feel like I'm maybe just running up against the "pseudo" of "pseudo-arrays".

— 0