include(CMakePrintHelpers)
file(READ "${CMAKE_CURRENT_LIST_DIR}/example.json" json_contents)

string(JSON value ERROR_VARIABLE err TYPE "${json_contents}" name)
if(NOT err)
    cmake_print_variables(value)
else()
    cmake_print_variables(err)
endif()
string(JSON value ERROR_VARIABLE err GET "${json_contents}" name)
if(NOT err)
    cmake_print_variables(value)
else()
    cmake_print_variables(err)
endif()

string(JSON value ERROR_VARIABLE err TYPE "${json_contents}" array)
if(NOT err)
    cmake_print_variables(value)
else()
    cmake_print_variables(err)
endif()
string(JSON value ERROR_VARIABLE err GET "${json_contents}" array)
if(NOT err)
    cmake_print_variables(value)
else()
    cmake_print_variables(err)
endif()
string(JSON value ERROR_VARIABLE err LENGTH "${json_contents}" array)
if(NOT err)
    cmake_print_variables(value)
else()
    cmake_print_variables(err)
endif()

string(JSON value ERROR_VARIABLE err GET "${json_contents}" array 1 a3)
if(NOT err)
    cmake_print_variables(value)
else()
    cmake_print_variables(err)
endif()
string(JSON value ERROR_VARIABLE err TYPE "${json_contents}"  array 1 )
if(NOT err)
    cmake_print_variables(value)
else()
    cmake_print_variables(err)
endif()
string(JSON value ERROR_VARIABLE err TYPE "${json_contents}" object)
if(NOT err)
    cmake_print_variables(value)
else()
    cmake_print_variables(err)
endif()
string(JSON value ERROR_VARIABLE err LENGTH "${json_contents}" object)
if(NOT err)
    cmake_print_variables(value)
else()
    cmake_print_variables(err)
endif()
string(JSON value ERROR_VARIABLE err GET "${json_contents}" object objnumber)
if(NOT err)
    cmake_print_variables(value)
else()
    cmake_print_variables(err)
endif()

string(JSON value ERROR_VARIABLE err TYPE "${json_contents}" boolean)
if(NOT err)
    cmake_print_variables(value)
else()
    cmake_print_variables(err)
endif()
string(JSON value ERROR_VARIABLE err GET "${json_contents}" boolean)
if(NOT err)
    cmake_print_variables(value)
else()
    cmake_print_variables(err)
endif()

string(JSON value ERROR_VARIABLE err TYPE "${json_contents}" number)
if(NOT err)
    cmake_print_variables(value)
else()
    cmake_print_variables(err)
endif()
string(JSON value ERROR_VARIABLE err GET "${json_contents}" number)
if(NOT err)
    cmake_print_variables(value)
else()
    cmake_print_variables(err)
endif()

string(JSON value ERROR_VARIABLE err TYPE "${json_contents}" null)
if(NOT err)
    cmake_print_variables(value)
else()
    cmake_print_variables(err)
endif()
string(JSON value ERROR_VARIABLE err GET "${json_contents}" null)
if(NOT err)
    cmake_print_variables(value)
else()
    cmake_print_variables(err)
endif()

string(JSON value ERROR_VARIABLE err TYPE "${json_contents}" otherarray 0)
if(NOT err)
    cmake_print_variables(value)
else()
    cmake_print_variables(err)
endif()
string(JSON value ERROR_VARIABLE err TYPE "${json_contents}" otherarray 3)
if(NOT err)
    cmake_print_variables(value)
else()
    cmake_print_variables(err)
endif()


string(JSON value ERROR_VARIABLE err LENGTH "${json_contents}")
if(NOT err)
    cmake_print_variables(value)
else()
    cmake_print_variables(err)
endif()

message(STATUS "Length of JSON contents:'${value}'")
math(EXPR length "${value}-1")
foreach(json_index RANGE ${length})
    string(JSON member ERROR_VARIABLE err MEMBER "${json_contents}" ${json_index})
    if(err)
        cmake_print_variables(err)
    endif()
    string(JSON type ERROR_VARIABLE err TYPE "${json_contents}" ${member})
    if(err)
        cmake_print_variables(err)
    endif()
    string(JSON value ERROR_VARIABLE err GET "${json_contents}" ${member})
    if(err)
        cmake_print_variables(err)
    endif()

    message(STATUS "Member at index '${json_index}': '${member}':'${type}' = '${value}'")
endforeach()
# string(JSON value ERROR_VARIABLE err GET "${value}" 0)
# if(NOT err)
    # cmake_print_variables(value)
# else()
    # cmake_print_variables(err)
# endif()

# string(JSON value ERROR_VARIABLE err GET "${value}" a2)
# if(NOT err)
    # cmake_print_variables(value)
# else()
    # cmake_print_variables(err)
# endif()