I tried out cJSON and discovered that even if I give an correct JSON followed by an incorrect JSON, it takes the entire content into its parse_buffer
struct (in cJSON.c
) and parses only the correct JSON. I can easily get the length of the total parsed content by doing something like:
buffer.length
in cJSON.c
after the parsing is completed.
If I have a file which contains something like:
{
"text": "HelloWorld!!"
}
{
"text" : "incompletejson"
the cJSON puts the entire contents into its buffer and parses only the valid part.
If in my program I write:
//open file and read contents in buffer
/* Parse buffer into cJSON structure */
cJSON *root = cJSON_Parse(buffer);
char *text = cJSON_GetObjectItem(root, "text")->valuestring;
printf("text: %s\n", text);
it prints out HelloWorld!!
.
Is there a way to get the length of just the parsed content i.e., the correct JSON that has been parsed? Is this at all possible in cJSON?