summaryrefslogtreecommitdiffstats
path: root/sca-cpp/trunk/modules
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--sca-cpp/trunk/modules/json/json-test.cpp18
-rw-r--r--sca-cpp/trunk/modules/json/json.hpp2
2 files changed, 19 insertions, 1 deletions
diff --git a/sca-cpp/trunk/modules/json/json-test.cpp b/sca-cpp/trunk/modules/json/json-test.cpp
index 157e012b5a..ac68d7573d 100644
--- a/sca-cpp/trunk/modules/json/json-test.cpp
+++ b/sca-cpp/trunk/modules/json/json-test.cpp
@@ -66,6 +66,13 @@ const string jsecho("{\n"
" }\n"
"}");
+const string jsarray("{\n"
+ " \"fruit\": [\n"
+ " \"Apple\",\n"
+ " \"Orange\"\n"
+ " ]\n"
+ "}");
+
bool testJSON() {
const js::JSContext cx;
@@ -107,6 +114,17 @@ bool testJSON() {
const list<value> r = elementsToValues(content(readJSON(il, cx)));
assert(r == l);
}
+ {
+ const list<value> l = mklist<value>((list<value>() + "fruit" + string("Apple")), (list<value>() + "fruit" + string("Orange")));
+ ostringstream wos;
+ write(content(writeJSON(valuesToElements(l), cx)), wos);
+ assert(str(wos) == jsarray);
+
+ istringstream is(str(wos));
+ const list<string> il = streamList(is);
+ const list<value> r = elementsToValues(content(readJSON(il, cx)));
+ assert(r == l);
+ }
return true;
}
diff --git a/sca-cpp/trunk/modules/json/json.hpp b/sca-cpp/trunk/modules/json/json.hpp
index e222ef0486..39c56b6863 100644
--- a/sca-cpp/trunk/modules/json/json.hpp
+++ b/sca-cpp/trunk/modules/json/json.hpp
@@ -122,7 +122,7 @@ template<typename R> const failable<R> writeJSON(const lambda<R(const string&, c
* Convert a list of values to a list of strings representing a JSON document.
*/
const failable<list<string> > writeJSON(const list<value>& l, const js::JSContext& cx) {
- const failable<list<string> > ls = writeJSON<list<string>>(rcons<string>, list<string>(), l, cx);
+ const failable<list<string> > ls = writeJSON<list<string>>(rcons<string>, list<string>(), valuesToElements(elementsToValues(l)), cx);
if (!hasContent(ls))
return ls;
return reverse(list<string>(content(ls)));