How 2 count number of elements in json array using string(json

Simple usage question here. If I want to count the size of a json array

  • read json file
  • count number of entryies in top level array
  • save number of entries as a variable
    file(read JSON input.json input)
    string(JSON len LENGTH ${input} 0 ARRAY_MEMBERS)
    set( length_of_array ${len})

I think this would work better:

file(READ "input.json" input)
string(JSON length_of_array LENGTH "${input}" "")

though I’m not 100% sure on how to reference the top-level object/array (that last empty string argument).