Zero the visited flag after encoding an empty array or object
[jansson.git] / src / dump.c
index bc06dfd..a36da03 100644 (file)
@@ -231,8 +231,10 @@ static int do_dump(const json_t *json, unsigned long flags, int depth,
 
             if(dump("[", 1, data))
                 return -1;
-            if(n == 0)
+            if(n == 0) {
+                array->visited = 0;
                 return dump("]", 1, data);
+            }
             if(dump_indent(flags, depth + 1, 0, dump, data))
                 return -1;
 
@@ -284,8 +286,10 @@ static int do_dump(const json_t *json, unsigned long flags, int depth,
 
             if(dump("{", 1, data))
                 return -1;
-            if(!iter)
+            if(!iter) {
+                object->visited = 0;
                 return dump("}", 1, data);
+            }
             if(dump_indent(flags, depth + 1, 0, dump, data))
                 return -1;