Inspection & navigation¶
json_type¶
Writes the node's type into out_type. Returns 1 on success, 0 if the handle
is missing.
enum {
JSON_TYPE_NULL = 0,
JSON_TYPE_BOOL,
JSON_TYPE_NUMBER,
JSON_TYPE_STRING,
JSON_TYPE_ARRAY,
JSON_TYPE_OBJECT,
}
json_is_array / json_is_object¶
Return 1/0 directly. Handy shortcuts over json_type.
json_len¶
Writes the element count into out_len: array length, object key count, or 0
for scalars. Returns 1 on success, 0 if the handle is missing.
Iterating object keys¶
native json_object_len(ptr, &out_len);
native json_object_key_at(ptr, index, output[], size = sizeof(output));
native json_key_at(ptr, index, output[], size = sizeof(output)); // object only
json_object_len writes the key count; json_object_key_at / json_key_at read
the key name at a given position (insertion order). They return 0 (and log
E030/E031/E048) if the handle is not an object, or E032 for an
out-of-range index.
new n;
json_object_len(doc, n);
for (new i = 0; i < n; i++)
{
new key[32];
json_object_key_at(doc, i, key);
printf("key[%d] = %s", i, key);
}
json_item¶
Deep-copies the element at index of an array handle into a new handle
written to out_ptr. Returns 1 on success; 0 for a non-array (E049),
missing handle (E047) or out-of-range index (E032).
Warning
The result is a new handle — free it with json_free.
json_at¶
Deep-copies the node reachable at path into a new handle. Returns 1 on
success; 0 for a missing handle (E040) or unresolved path (E041). The result
is a new handle — free it.