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
14
votes
4 answers

Using cJSON to read in a JSON array

I am attempting to use the cJSON library, written by Dave Gamble, to read in the following JSON array: "items": [ { "name": "command", "index": "X", "optional": "0" }, { "name": "status", "index":…
Nealon
  • 2,213
  • 6
  • 26
  • 40
7
votes
3 answers

create json object using cJSON.h

I am trying to create JSON object like below but I am not able to add the second item in it e.g: "CarType": "mercedes", "carID": "merc123" and also other items. I want to create JSON like this: { cars: [ { "CarType": "BMW", …
Abhishek
  • 133
  • 1
  • 2
  • 9
6
votes
2 answers

What is the JSON Standard for an empty string or null variable?

I'm building an application that parses a JSON template and then replaces the values of the objects with new data. My question is what is the standard way to represent empty data in JSON? This is how I'm handling this right now: an empty string is…
Austen Stone
  • 948
  • 1
  • 10
  • 21
6
votes
1 answer

Redis Lua Differetiating empty array and object

I encountered this bug in cjson lua when I was using a script in redis 3.2 to set a particular value in a json object. Currently, the lua in redis does not differentiate between an empty json array or an empty json object. Which causes serious…
tanvi
  • 927
  • 5
  • 17
  • 32
5
votes
1 answer

Lua cannot find installed luarocks on Ubuntu

I install luarocks: $ sudo apt-get install luarocks I install lua-cjson by luarocks: $sudo luarocks install lua-cjson show packages: $luarocks list Installed rocks: ---------------- lua-cjson 2.1.0-1 (installed) -…
Alexandre Kalendarev
  • 681
  • 2
  • 10
  • 24
4
votes
2 answers

iterate an cJSON nested object in c

How to iterate nested cJSON object? i want to get(print) all keys and values from deviceData parent object in C. Its a cJson object. obj = { "command": "REPLACE_ROWS", "table": "Device.XXX", "deviceData": { …
selvam
  • 59
  • 1
  • 5
3
votes
1 answer

cJSON_Print dosen't show updated values

Im using cJSON by Dave Gamble and have the following problem. If I change the value within a cJSON struct and then use the cJSON_Print command I dont get the updated values, instead I still get the default ones. #include #include…
PaulB
  • 73
  • 6
3
votes
2 answers

Should the return value of cJSON_Print() be freed by the caller?

I am using the cJSON library and I have a function as follows: void printJsonObject(cJSON *item) { char *json_string = cJSON_Print(item); printf("%s\n", json_string); } Will this function leak memory?
hopia
  • 4,880
  • 7
  • 32
  • 54
3
votes
2 answers

cJSON memory leak

I use cJSON in my program to convert my values to JSON and write it to file. Here is the example of my code: void writeStructToFile(IOPipe this, struct structtype somevalues) { cJSON *jout = cJSON_CreateObject(); cJSON_AddItemToObject(jout,…
PaulPonomarev
  • 355
  • 1
  • 4
  • 20
3
votes
2 answers

C lib to read and parse JSON directly from file stream

I have seen a number of libs for parsing JSON in C but none of them can read and parse directly from file streams. The problem with all such libs e.g Yajl, cjson is that if the json document in the file is huge then you have to first read all of…
auny
  • 1,920
  • 4
  • 20
  • 37
2
votes
0 answers

How do i split the CJSON parsing or cJSON_Print

I have checked the documentation: https://github.com/DaveGamble/cJSON#parsing-json and https://github.com/DaveGamble/cJSON#printing-json. My question is I have a function void foo (char *JSON); that can only accept size_t JSON string representation…
NewUser
  • 41
  • 5
2
votes
1 answer

cJSON_Delete() and cJSON_free()

am still new to the cJSON library and i cant fully understand the uses of cJSON_Delete() and cJSON_free(), Is there any document that accurately describes what functions should be released, also when to use cJSON_free() and when to use…
FaruK
  • 23
  • 8
2
votes
2 answers

query parameter preserve as json

I'm trying to store API request query parameters in JSON format, in a way that preserves the inferred original types of the parameters' values. I do this without knowing what these APIs look like beforehand. The code below deals with each query…
ajfbiw.s
  • 401
  • 1
  • 8
  • 22
2
votes
1 answer

I don't understand how to use cJSON to parse a JSON file into a struct

I have a fairly simple struct Message which contains two fields of type Envelope. struct Envelope { char* Payload; //Byte array of message data char* Signature; //Byte array for signature of endorser }; struct Message { char* configSeq;…
Caleb Johnson
  • 376
  • 3
  • 21
2
votes
1 answer

How can we add a new item to a parsed JSON with cJSON?

I am programming a server for my client that keeps messages. I keep them in JSON format using cJSON -by Dave Gambler- And save them in a text file. how can I add a new item to my Array after reading the string from file and parsing it? The JSON…
Ali Hatami
  • 144
  • 10
1
2 3 4 5 6 7 8