Understand the cJSON data structure
mastercJSON represents JSON values using the cJSON struct. Each item is a node in a linked list (for arrays and objects) or a standalone value.
Key Fields:
next/prev: Pointers for linked list traversal.child: Pointer to the first child (used for objects and arrays).type: A bit-flag representing the JSON type.valuestring: A zero-terminated string forcJSON_StringorcJSON_Rawtypes.valueint: Integer representation of a number.valuedouble: Double representation of a number.string: The key name for items within acJSON_Object.
Important: Type Checking
Because type is a bit-flag, you must not use direct equality comparisons (e.g., item->type == cJSON_Number). Instead, use the provided cJSON_Is... functions (e.g., cJSON_IsNumber(item)), which handle NULL checks and bit-flag logic correctly.
typedef struct cJSON
{
struct cJSON *next;
struct cJSON *prev;
struct cJSON *child;
int type;
char *valuestring;
int valueint;
double valuedouble;
char *string;
} cJSON;