From 1eb5ea3a641dc5c2d722c31282b8a4f19df5f99e Mon Sep 17 00:00:00 2001 From: Kyle Edwards Date: Tue, 16 Dec 2025 10:19:49 -0500 Subject: [PATCH] Help(string(JSON)): Clarify that some modes can have zero members/indices --- Help/command/string.rst | 11 +++++++---- Tests/RunCMake/string/JSON.cmake | 17 +++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/Help/command/string.rst b/Help/command/string.rst index f0fb53dc3b..5bae624da7 100644 --- a/Help/command/string.rst +++ b/Help/command/string.rst @@ -46,7 +46,10 @@ Synopsis `JSON`_ string(JSON [ERROR_VARIABLE ] - {`GET `__ | `GET_RAW `__ | `TYPE `__ | `LENGTH `__ | `REMOVE `__} + {`GET `__ | `GET_RAW `__ | `TYPE `__ | `LENGTH `__} + [ ...]) + string(JSON [ERROR_VARIABLE ] + `REMOVE `__ [ ...]) string(JSON [ERROR_VARIABLE ] `MEMBER `__ @@ -551,7 +554,7 @@ string is passed as a single argument even if it contains semicolons. .. signature:: string(JSON [ERROR_VARIABLE ] - GET [ ...]) + GET [ ...]) :target: JSON-GET Get an element from ```` at the location given @@ -563,7 +566,7 @@ string is passed as a single argument even if it contains semicolons. .. signature:: string(JSON [ERROR_VARIABLE ] - GET_RAW [ ...]) + GET_RAW [ ...]) :target: JSON-GET-RAW Get an element from ```` at the location given @@ -573,7 +576,7 @@ string is passed as a single argument even if it contains semicolons. .. signature:: string(JSON [ERROR_VARIABLE ] - TYPE [ ...]) + TYPE [ ...]) :target: JSON-TYPE Get the type of an element in ```` at the location diff --git a/Tests/RunCMake/string/JSON.cmake b/Tests/RunCMake/string/JSON.cmake index 3bfb4d071c..1a988e193f 100644 --- a/Tests/RunCMake/string/JSON.cmake +++ b/Tests/RunCMake/string/JSON.cmake @@ -120,6 +120,17 @@ if(result) message(SEND_ERROR "Output did not match expected: FALSE actual: ${result}") endif() +string(JSON result GET "\"Hello\"") +assert_strequal("${result}" Hello) +string(JSON result GET "5") +assert_strequal("${result}" 5) +string(JSON result GET "null") +assert_strequal("${result}" "") +string(JSON result ERROR_VARIABLE error GET "{}") +assert_json_equal("${error}" "${result}" "{}") +string(JSON result ERROR_VARIABLE error GET "[]") +assert_json_equal("${error}" "${result}" "[]") + string(JSON result ERROR_VARIABLE error GET "${json1}" foo) assert_strequal_error("${result}" "bar" "${error}") @@ -233,6 +244,12 @@ string(JSON result TYPE "${json1}" types array) assert_strequal("${result}" ARRAY) string(JSON result TYPE "${json1}" types object) assert_strequal("${result}" OBJECT) +string(JSON result TYPE "null") +assert_strequal("${result}" NULL) +string(JSON result TYPE "5") +assert_strequal("${result}" NUMBER) +string(JSON result TYPE "\"Hello\"") +assert_strequal("${result}" STRING) # Test LENGTH string(JSON result ERROR_VARIABLE error LENGTH "${json1}")