diff options
| author | Joey Adams | 2010-06-15 02:49:13 +0000 |
|---|---|---|
| committer | Joey Adams | 2010-06-15 02:49:13 +0000 |
| commit | 599940cb2fcde6e26b095b8accf7c3a70b2ba05b (patch) | |
| tree | a16053467276d9c009904718bddb910519159e88 /json.c | |
| parent | 58b696fc6c16123fb8206c386d6d398e47a6c21f (diff) | |
Initial implementation of json_path function.
Currently, it re-encodes JSON nodes rather than preserving original text.
This is subject to change.
Diffstat (limited to 'json.c')
| -rw-r--r-- | json.c | 13 |
1 files changed, 9 insertions, 4 deletions
@@ -803,11 +803,11 @@ char *json_encode(json_node *node) { String(ret); const char *txt; - json_node *sentinel; + json_node *root; if (!node) return NULL; - sentinel = node->parent; + root = node; goto begin_nokey; @@ -866,15 +866,20 @@ finish: /* Finish a node and move to the next one. */ string_append_char(ret, ']'); else if (node->type == JSON_OBJECT) string_append_char(ret, '}'); - + + if (node == root) + goto end; + if (node->next) { string_append_char(ret, ','); node = node->next; goto begin; } - if (node->parent != sentinel) { + if (node->parent) { node = node->parent; goto finish; + } else { + Assert(false); } goto end; |
