How to convert json array to cmake list variable

Suppose I have part of a json: "dir": ["a/b", "c/d" ] , how should I get a cmake list variable like:
set(var "a/b" "c/d") via string(JSON

If json is {"name":"foo"}, I can get foo from string(JSON cur_name GET ${MY_JSON_STRING} ${IDX} name). But I don’t know how to iterate over a json array.

You’ll need to get the length and build up an array using string(JSON out GET json${n}).

1 Like