Open escherstair opened 7 months ago
I think you can just call cJSON_IsArray
or cJSON_IsObject
without having to look into the cJSON structure yourself and read child
. These functions both return false if the item passed is NULL.
Hi @mbratch,
sorry for the confusion, but I'm not interested in finding if the item is NULL.
I need to detect if it points to an empty json object {}
or empty json array []
.
@escherstair I see thanks for clarifying, I misunderstood.
I suppose it may be an application-specific need. If it were a common pattern in my application, I'd just write my own little function for it.
If you think it's not a general use case, for me it's ok going on witth the little custom function I wrote.
Sometimes it's require dto check if a JSON object or array is empty. As far as I understand, this requires looking to
json->child
, as done insidecJSON_GetArraySize()
https://github.com/DaveGamble/cJSON/blob/87d8f0961a01bf09bef98ff89bae9fdec42181ee/cJSON.c#L1833-L1854I would suggest adding a new function, as an example:
What do you think?