Parsing JSON from HTTP Response

I am currently expanding on the https_client example project using the NRF9160 and I am successful in connecting to my cloud instance and executing commands with my HTTPS API.  The problem is that I am not sure how to parse out the JSON response in the body of the HTTPS response.

I am able to isolate the JSON portion of the HTTPS response, but the content is seemingly unintelligible, see screenshot below:

When I attempt to use the cJSON library, my project won't compile, which was the main contributor to moving away from the azure_iot_hub example.  Terminal output below:

Building https_client
west build --build-dir c:\ncs\v2.0.0\nrf\samples\nrf9160\https_client\build c:\ncs\v2.0.0\nrf\samples\nrf9160\https_client

[0/17] Performing build step for 'tfm'
ninja: no work to do.
[2/14] Building C object CMakeFiles/app.dir/src/main.c.obj
FAILED: CMakeFiles/app.dir/src/main.c.obj 
C:\ncs\toolchains\v2.0.0\opt\zephyr-sdk\arm-zephyr-eabi\bin\arm-zephyr-eabi-gcc.exe -DKERNEL -DMBEDTLS_CONFIG_FILE=\"nrf-config.h\" -DMBEDTLS_USER_CONFIG_FILE=\"nrf-config-user.h\" -DNRF9160_XXAA -DNRF_SKIP_FICR_NS_COPY_TO_RAM -DNRF_TRUSTZONE_NONSECURE -DTFM_PSA_API -DUSE_PARTITION_MANAGER=1 -D_FORTIFY_SOURCE=2 -D__LINUX_ERRNO_EXTENSIONS__ -D__PROGRAM_START -D__ZEPHYR__=1 -IC:/ncs/v2.0.0/zephyr/include/zephyr -IC:/ncs/v2.0.0/zephyr/include -Izephyr/include/generated -IC:/ncs/v2.0.0/zephyr/soc/arm/nordic_nrf/nrf91 -IC:/ncs/v2.0.0/zephyr/lib/libc/newlib/include -IC:/ncs/v2.0.0/zephyr/soc/arm/nordic_nrf/common/. -IC:/ncs/v2.0.0/zephyr/subsys/net/lib/sockets/. -IC:/ncs/v2.0.0/nrf/include -IC:/ncs/v2.0.0/nrf/lib/at_cmd_parser/include -IC:/ncs/v2.0.0/nrf/include/tfm -Itfm/generated/interface/include -IC:/ncs/v2.0.0/modules/hal/cmsis/CMSIS/Core/Include -IC:/ncs/v2.0.0/modules/hal/nordic/nrfx -IC:/ncs/v2.0.0/modules/hal/nordic/nrfx/drivers/include -IC:/ncs/v2.0.0/modules/hal/nordic/nrfx/mdk -IC:/ncs/v2.0.0/zephyr/modules/hal_nordic/nrfx/. -IC:/ncs/v2.0.0/nrfxlib/nrf_modem/include -Itfm/install/interface/include -Imodules/nrfxlib/nrfxlib/nrf_security/src/include/generated -IC:/ncs/v2.0.0/nrfxlib/nrf_security/include -IC:/ncs/v2.0.0/nrfxlib/nrf_security/include/mbedtls -IC:/ncs/v2.0.0/mbedtls/include -IC:/ncs/v2.0.0/mbedtls/include/mbedtls -IC:/ncs/v2.0.0/mbedtls/include/psa -IC:/ncs/v2.0.0/mbedtls/library -IC:/ncs/v2.0.0/nrfxlib/crypto/nrf_oberon/include/mbedtls -IC:/ncs/v2.0.0/nrfxlib/crypto/nrf_oberon/include -Og -imacros C:/ncs/v2.0.0/nrf/samples/nrf9160/https_client/build/zephyr/include/generated/autoconf.h -ffreestanding -fno-common -g -gdwarf-4 -fdiagnostics-color=always -mcpu=cortex-m33 -mthumb -mabi=aapcs -mfp16-format=ieee -imacros C:/ncs/v2.0.0/zephyr/include/zephyr/toolchain/zephyr_stdint.h -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wno-main -Wno-pointer-sign -Wpointer-arith -Wexpansion-to-defined -Wno-unused-but-set-variable -Werror=implicit-int -fno-asynchronous-unwind-tables -fno-pie -fno-pic -fno-reorder-functions -fno-defer-pop -fmacro-prefix-map=C:/ncs/v2.0.0/nrf/samples/nrf9160/https_client=CMAKE_SOURCE_DIR -fmacro-prefix-map=C:/ncs/v2.0.0/zephyr=ZEPHYR_BASE -fmacro-prefix-map=C:/ncs/v2.0.0=WEST_TOPDIR -ffunction-sections -fdata-sections -specs=nano.specs -std=c99 -MD -MT CMakeFiles/app.dir/src/main.c.obj -MF CMakeFiles\app.dir\src\main.c.obj.d -o CMakeFiles/app.dir/src/main.c.obj -c ../src/main.c
c:\ncs\v2.0.0\nrf\samples\nrf9160\https_client\src\main.c:16:10: fatal error: cJSON.h: No such file or directory
   16 | #include <cJSON.h>
      |          ^~~~~~~~~
compilation terminated.
ninja: build stopped: subcommand failed.
FATAL ERROR: command exited with status 1: 'c:\ncs\toolchains\v2.0.0\opt\bin\cmake.EXE' --build 'c:\ncs\v2.0.0\nrf\samples\nrf9160\https_client\build'
The terminal process terminated with exit code: 1.

Terminal will be reused by tasks, press any key to close it.

My prj.conf file below:

CONFIG_NRF_MODEM_LIB=y

CONFIG_NETWORKING=y
CONFIG_NET_SOCKETS=y
CONFIG_NET_SOCKETS_POSIX_NAMES=y
CONFIG_NET_NATIVE=n

CONFIG_HEAP_MEM_POOL_SIZE=1024
CONFIG_MAIN_STACK_SIZE=2048

CONFIG_MODEM_KEY_MGMT=y
CONFIG_LTE_LINK_CONTROL=y
CONFIG_LTE_AUTO_INIT_AND_CONNECT=n

# nothing here
CONFIG_CJSON_LIB=y

# newlibc
CONFIG_NEWLIB_LIBC=y

I am using VS Code with the nRF Connect Plugin and the nRF Connect for Desktop to manage the toolchain.  I am using the 2.0.0 toolchain.

Related