6 #define KSON_TYPE_NO_QUOTE 1
7 #define KSON_TYPE_SGL_QUOTE 2
8 #define KSON_TYPE_DBL_QUOTE 3
9 #define KSON_TYPE_BRACKET 4
10 #define KSON_TYPE_BRACE 5
13 #define KSON_ERR_EXTRA_LEFT 1
14 #define KSON_ERR_EXTRA_RIGHT 2
15 #define KSON_ERR_NO_KEY 3
17 typedef struct kson_node_s
{
18 unsigned long long type
:3, n
:61;
21 struct kson_node_s
**child
;
35 kson_t
*kson_parse(const char *json
);
36 void kson_destroy(kson_t
*kson
);
37 const kson_node_t
*kson_by_path(const kson_node_t
*root
, int path_len
, ...);
38 void kson_format(const kson_node_t
*root
);
44 #define kson_is_internal(p) ((p)->type == KSON_TYPE_BRACKET || (p)->type == KSON_TYPE_BRACE)
46 static inline const kson_node_t
*kson_by_key(const kson_node_t
*p
, const char *key
)
49 if (!kson_is_internal(p
)) return 0;
50 for (i
= 0; i
< (long)p
->n
; ++i
) {
51 const kson_node_t
*q
= p
->v
.child
[i
];
52 if (q
->key
&& strcmp(q
->key
, key
) == 0)
58 static inline const kson_node_t
*kson_by_index(const kson_node_t
*p
, long i
)
60 if (!kson_is_internal(p
)) return 0;
61 return 0 <= i
&& i
< (long)p
->n
? p
->v
.child
[i
] : 0;