Questions tagged [cjson]

cJSON aims to be the dumbest possible parser that you can get your job done with. It's a single file of C, and a single header file.

cJSON aims to be the dumbest possible parser that you can get your job done with. It's a single file of C, and a single header file.

110 questions
0
votes
0 answers

Clear all values from cjson object

I want to clear all values from my cjson object. My object is to reuse the cjson object for entirely different purpose, so I want to make sure that I start fresh. At the end of the clear operation my cjson object should look as below. {} Can…
srib
  • 148
  • 2
  • 13
0
votes
1 answer

Compare cJSON objects in the same code every time program is executed

I have a code which is always running in the background. compareContents() reads contents from a file periodically (based on an event) and stores it in a cSJON object. I have to compare current contents of the file (cJSON object) with the previous…
bvj0412
  • 17
  • 5
0
votes
0 answers

Chances of memory leak in cJSON_Print in CPP

I have seen multiple documentation citing that use of cJSON_Print like the below example needs to be accompanied with a call for free(), else it will cause a memory leak. char* char_json = cJSON_Print(jsonvar) Will I get a memory leak issue if I…
0
votes
0 answers

why does cJSON behave this way when using nested JSON?

I'm trying to overwrite items within a JSON File with the content of another JSON file while using cJSON. before explaining further these are my 2 JSON documents: the first one: { "Data": { "baud" : 9600 , …
Dansen
  • 55
  • 1
  • 8
0
votes
1 answer

Iterating through a cJSON Array alternatively

This is the code I am using cJSON *IDs = cJSON_GetObjectItem(tree, "fruitIds"); cJSON *mangoe; cJSON_ArrayForEach(mangoe, IDs) { } My JSON object looks something like this static char *buffer =…
Senuda Jayalath
  • 88
  • 1
  • 12
0
votes
0 answers

memory leak using cJson ESP32

Please could someone help me to identify why there is a memory leak using cJson I could not find the problem. whenever I do an authentication the live memory decreases. The json is created only at that point, I have already changed the control logic…
Pedrojdi
  • 17
  • 4
0
votes
1 answer

cJSON_Delete(); causes free(): invalid pointer: 0xb5db1e18

code cJSON *body = cJSON_Duplicate(record, true); cJSON_AddItemToObject(body, KEY_LOG, log); cJSON *array_pl = cJSON_CreateArray(); cJSON_AddItemToArray(array_pl, body); cJSON *payload = cJSON_CreateObject(); …
0
votes
0 answers

Declaration of index in string.h overshadowed by cJSON.h

I am trying to make a C++ program that makes use of the string.h and cJSON library. But when I build it, I get warning saying: cJSON.c:1743: warning: declaration of 'index' shadows a global declaration string.h:487: warning: shadowed declaration is…
Shantanu Shinde
  • 932
  • 3
  • 23
  • 48
0
votes
1 answer

cJSON Memory leak when freeing cJSON object

I am facing an issue while using the cJSON Library. I am assuming that there is a memory leak that is breaking the code after a certain time (40 mins to 1 hr). I have copied my code below : void my_work_handler_5(struct k_work *work) { char…
Adeel Ahmed
  • 43
  • 1
  • 4
0
votes
1 answer

Printing Allocated cJSON cString inside Struct triggers EXC_BAD_ACCESS (Segmentation Fault) C lang

I can't fix this bug: After returning the vector struct and printing it (main.c) I get a seg fault. EXC_BAD_ACCESS typically means that the memory address pointed to is not allocated. But I never deallocated the parsed JSON (cJSON_Delete(cJSON…
0
votes
1 answer

how can we pass a return value as a input to a same function in c

In this function outdata to store a output then it pass as a input to this function then update the outputdata again pass then update like this manner. again pass as input then update the outputdat. char…
Goudam M
  • 19
  • 2
0
votes
1 answer

is there way to create array without key in cJSON

1.i need print json format like { "numport":1 [ { "Port":1 "value":234 },{ "Port":2 "value":2344 } ]
Goudam M
  • 19
  • 2
0
votes
0 answers

malloc function in MSVC and linux is different in cJSON

While I studying cJSON source code, I don't understand why they use different malloc functions, instead of using a wrapper. typedef struct internal_hooks { void *(CJSON_CDECL *allocate)(size_t size); void (CJSON_CDECL *deallocate)(void…
0
votes
2 answers

Publishing JSON object through MQTT to AWS IoT from ESP32 using C and ESP-IDF framework

I have a structure IoT_Publish_Message_Params that needs to be prepared in order to prepare a publishing on AWS IoT. The below snippet works completely fine when I'm passing a string as the payload. /** * @brief Publish Message Parameters Type * …
0
votes
0 answers

Function return via pointer doesn't work correctly

I am not so experienced in programming in C and I occurred a problem. I'm trying to pass cJSON* body_json to a function int _parseJSON(const char* const body, cJSON* body_json) via pointer. In this function, I want to change body_json and return it…
cropyeee
  • 23
  • 1
  • 3