return Value().take_ownership(json_loads(string, error));
}
+ // write the value to a file
+ int save_file(const char* path, int flags = JSON_INDENT(2)) const {
+ return json_dump_file(_value, path, flags);
+ }
+
+ // write the value to a string (caller must deallocate with free()!)
+ char* save_string(int flags = JSON_INDENT(2)) const {
+ return json_dumps(_value, flags);
+ }
+
// construct Value from input
static Value from(const char* value) { return Value().take_ownership(json_string(value)); }
static Value from(const std::string& value) { return from(value.c_str()); }
#include <iostream>
#include <iomanip>
+#include <malloc.h>
#include "janssonxx.h"
e3.clear();
ASSERT_EQ(e3.size(), 0, "e3 has incorrect number of properties after clear");
+ e3 = jansson::Value::object();
+ e3.set("foo", jansson::Value::from("test"));
+ e3.set("bar", jansson::Value::from(3));
+ char* out_cstr = e3.save_string(0);
+ string out(out_cstr);
+ free(out_cstr);
+ ASSERT_EQ(out, "{\"bar\": 3,\"foo\": \"test\"}\n", "object did not serialize as expected");
+
return 0;
}