CForgeJSON¶
This module provides functions for parsing JSON strings in CMake scripts using
string(JSON).
Note
requires CMake 3.19 or greater
- cforge_json_member_as_string¶
Convert a CMake JSON member list into a more readable fragment identifier based on JSON Pointers (RFC6901). Named members will add
/member, whereas indexes will add a/indexto the result variable. The identifier will start with # to denote the root.cforge_json_member_as_string( RESULT_VARIABLE <out-var> MEMBER <member|index> [<member|index> ...] )
Usage example
cforge_json_member_as_string( RESULT_VARIABLE MEMBER_STRING MEMBER abc def 2 ghi )
The member list
abc def 2 ghiwill be converted into#/abc/def/2/ghiand stored intoMEMBER_STRINGresult 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> 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
<out-var>for later processing.If the JSON element designated by the
<member|index>arguments is not found and theOPTIONALboolean argument is used, then the returned list<out-var>will be empty. Otherwise a fatal error is thrown.Parameters
OPTIONALDo not throw an error if the JSON member is not found.
Usage example
cforge_json_get_array_as_list( ... )
Desc