How to include cJSON?

ryanf55
Posts: 8
Joined: Sun Mar 22, 2020 7:15 am

How to include cJSON?

Postby ryanf55 » Thu Aug 27, 2020 7:06 am

Hello,

I am using ESPIDFv4.0 and would like to include cJSON. None of the following work:

#include <cJSON/cJSON.h>
#include <cJSON.h>
#include <json/cJSON/cJSON.h>

What do I need to use in order to use cJSON in my code?

ESP-Marius
Posts: 74
Joined: Wed Oct 23, 2019 1:49 am

Re: How to include cJSON?

Postby ESP-Marius » Thu Aug 27, 2020 7:27 am

#include <cJSON.h> should work. Remember to also include

Code: Select all

REQUIRES json
in your CMakeList.txt if you are trying to use it outside your main component.

ryanf55
Posts: 8
Joined: Sun Mar 22, 2020 7:15 am

Re: How to include cJSON?

Postby ryanf55 » Thu Aug 27, 2020 5:10 pm

Thank you, yes have a few of my own components that are needing cJSON. Your suggestions worked.

For anyone else needing assistance, here's the contents of the cv_server CMakeLists.txt, noting the addition of requiring json.

Code: Select all

idf_component_register(SRCS "cv_server.c"
                       INCLUDE_DIRS "include"
                       REQUIRES esp_http_server cv_mqtt cv_ota json
                       EMBED_TXTFILES 
                           WebsiteFiles/settings.html 
                           WebsiteFiles/httpDocBegin.html
                           WebsiteFiles/httpDocConclude.html
                           WebsiteFiles/subtitle.html
                           WebsiteFiles/title.html
                           WebsiteFiles/wifiSettings.html
                           WebsiteFiles/test.html
                           WebsiteFiles/menuBar.html
                           WebsiteFiles/menuBarTest.html
                       )
                   
Here's the abbreviated folder structure. I bolded the files that are changed to use json.

ryan@ryan-Precision-5820-Tower:~/Development/personal/cv/clearview_interface_public/src/cvesp32$ tree -L 4
.
├── CMakeLists.txt
├── components
│ ├── cv_server
│ │ ├── CMakeLists.txt
│ │ ├── cv_server.c
│ │ ├── include
│ │ │ └── cv_server.h
│ │ └── WebsiteFiles
│ │ ├── menuBar.html
│ │ ├── settings.html
├── main
│ ├── CMakeLists.txt
│ ├── Kconfig.projbuild
│ └── main.c
├── sdkconfig
├── sdkconfig.defaults
└── version.txt

I was under the impression that any of the components in ESPIDF did not need to be required, but I was wrong.
Thanks!

eggnogg
Posts: 4
Joined: Sun Jan 17, 2021 5:27 pm

Re: How to include cJSON?

Postby eggnogg » Sun Oct 17, 2021 12:00 pm

For IDF 4.3.1 i had to add
set(REQUIRES json)

to CMakeLists.txt of my library

I thought it was working but it didn't finish building

this is the correct way

Code: Select all

set(COMPONENT_REQUIRES "json")

Who is online

Users browsing this forum: Bing [Bot], VinayDand and 142 guests