string(JSON SET) fails to handle strings that start with the `true` or `false` substring
Consider the following CMake example:
function(add_element json_blob_var key value)
string(JSON result ERROR_VARIABLE error SET "${${json_blob_var}}" ${key} ${value})
if(error)
string(JSON result ERROR_VARIABLE error SET "${${json_blob_var}}" ${key} "\"${value}\"")
endif()
set(${json_blob_var} "${result}" PARENT_SCOPE)
endfunction()
set(json [=[{ }]=])
add_element(json a 1)
add_element(json b false)
add_element(json c "[1,2,3]")
add_element(json e "string false")
add_element(json f string_false)
add_element(json g "false_string")
message(STATUS "result: ${json}")
This function attempts to add each item as the literal type to handle booleans
, `objects, etc. If that fails it adds them as string types.
In this case we see false_string
being incorrectly treated as the boolean false
Output:
-- result: {
"a" : 1,
"b" : false,
"c" : [ 1, 2, 3 ],
"e" : "string false",
"f" : "string_false",
"g" : false
}
Edited by Robert Maynard