#include <string.h>
#include <jansson.h>
+#include "jansson_private.h"
#include "strbuffer.h"
#define MAX_INTEGER_STR_LENGTH 100
case JSON_ARRAY:
{
int i;
- int n = json_array_size(json);
+ int n;
+ json_array_t *array;
+
+ /* detect circular references */
+ array = json_to_array(json);
+ if(array->visited)
+ return -1;
+ array->visited = 1;
+
+ n = json_array_size(json);
if(dump("[", 1, data))
return -1;
return -1;
}
}
+
+ array->visited = 0;
return dump("]", 1, data);
}
case JSON_OBJECT:
{
- void *iter = json_object_iter((json_t *)json);
+ json_object_t *object;
+ void *iter;
+
+ /* detect circular references */
+ object = json_to_object(json);
+ if(object->visited)
+ return -1;
+ object->visited = 1;
+
+ iter = json_object_iter((json_t *)json);
if(dump("{", 1, data))
return -1;
iter = next;
}
+
+ object->visited = 0;
return dump("}", 1, data);
}