summaryrefslogtreecommitdiff
path: root/json.c
diff options
context:
space:
mode:
authorJoey Adams2010-06-15 02:49:13 +0000
committerJoey Adams2010-06-15 02:49:13 +0000
commit599940cb2fcde6e26b095b8accf7c3a70b2ba05b (patch)
treea16053467276d9c009904718bddb910519159e88 /json.c
parent58b696fc6c16123fb8206c386d6d398e47a6c21f (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.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/json.c b/json.c
index 1cc8628..817f57f 100644
--- a/json.c
+++ b/json.c
@@ -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;