+
+void objcb(void *closure, struct json_object *obj, const char *key)
+{
+ const char *prefix = closure;
+ printf(" %s {%s} %s\n", prefix ?: "", key ?: "[]", json_object_to_json_string_ext(obj, JSON_C_TO_STRING_NOSLASHESCAPE));
+}
+
+void arrcb(void *closure, struct json_object *obj)
+{
+ objcb(closure, obj, NULL);
+}
+
+void tforall(struct json_object *object)
+{
+ wrap_json_for_all(object, objcb, "wrap_json_for_all");
+ wrap_json_optobject_for_all(object, objcb, "wrap_json_optobject_for_all");
+ wrap_json_object_for_all(object, objcb, "wrap_json_object_for_all");
+ wrap_json_optarray_for_all(object, arrcb, "wrap_json_optarray_for_all");
+ wrap_json_array_for_all(object, arrcb, "wrap_json_array_for_all");
+}
+
+struct mix
+{
+ int n;
+ struct json_object *pair[2];
+};
+
+void mixcb(void *closure, struct json_object *obj, const char *key)
+{
+ struct mix *mix = closure;
+
+ if (!mix->n) {
+ mix->pair[0] = json_object_new_object();
+ mix->pair[1] = json_object_new_object();
+ }
+ json_object_object_add(mix->pair[mix->n & 1], key, json_object_get(obj));
+ mix->n++;
+}
+
+void tmix(struct json_object *object)
+{
+ struct json_object *z;
+ struct mix mix = { .n = 0 };
+
+ wrap_json_object_for_all(object, mixcb, &mix);
+ if (mix.n) {
+ z = wrap_json_object_add(wrap_json_clone(mix.pair[0]), mix.pair[1]);
+ if (!wrap_json_contains(z, mix.pair[0]))
+ printf(" ERROR mix/1\n");
+ if (!wrap_json_contains(z, mix.pair[1]))
+ printf(" ERROR mix/2\n");
+ if (!wrap_json_contains(z, object))
+ printf(" ERROR mix/3\n");
+ if (!wrap_json_contains(object, z))
+ printf(" ERROR mix/4\n");
+ if (!wrap_json_equal(object, z))
+ printf(" ERROR mix/5\n");
+ json_object_put(z);
+ json_object_put(mix.pair[0]);
+ json_object_put(mix.pair[1]);
+ }
+}
+