CForgeJSON

Helper functions for parsing JSON strings in CMake scripts.

cforge_json_member_as_string

Convert a CMake JSON member list into a more readable JSON member path. Named members will add .member, whereas indexes will add a subscript [index] to the result variable.

cforge_json_member_as_string(
    RESULT_VARIABLE <out-var>
    MEMBER <member|index> [<member|index> ...]
)

Example invocation:

cforge_json_member_as_string(RESULT_VARIABLE MEMBER_STRING MEMBER abc def 2 ghi)

The member list abc def 2 ghi will be converted into abc.def[2].ghi and stored into MEMBER_STRING variable.

cforge_json_get_array_as_list

Get an array from <json-string> at the location given by the list of <member|index> arguments and copy its elements into the list variable <out-var>.

cforge_json_get_array_as_list(
    RESULT_VARIABLE <out-var>
    [RESULT_VARIABLE_OBJECTS <objects-out-var>]
    JSON <json-string>
    MEMBER <member|index> [<member|index> ...]
    [OPTIONAL]
)

If the JSON element designated by the <member|index> arguments is not an array but a single value, the <out-var> list will only contain that value.

If the values are JSON objects, the whole objects will be stored in the list <objects-out-var> for later processing. If the RESULT_VARIABLE_OBJECTS argument is not provided, the objects will be silently skipped.

If the JSON element designated by the <member|index> arguments is not found and the OPTIONAL boolean argument is used, then the returned list <out-var> will be empty. Otherwise a fatal error is thrown.