aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr/value-to-json.cc
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2013-11-19 00:33:06 +0100
committerEelco Dolstra <eelco.dolstra@logicblox.com>2013-11-19 00:33:06 +0100
commit5fea98111b3cd9b94ed1ebe89953a7757d6d3a69 (patch)
tree5a405678232c8602d7279439e68c13785b1100da /src/libexpr/value-to-json.cc
parent77c13cdf566ffedc70d8860571afae8a6d43b552 (diff)
Refactor JSON output
Diffstat (limited to 'src/libexpr/value-to-json.cc')
-rw-r--r--src/libexpr/value-to-json.cc19
1 files changed, 6 insertions, 13 deletions
diff --git a/src/libexpr/value-to-json.cc b/src/libexpr/value-to-json.cc
index 671a3c119..a2004df5c 100644
--- a/src/libexpr/value-to-json.cc
+++ b/src/libexpr/value-to-json.cc
@@ -1,5 +1,4 @@
-#include "value-to-xml.hh"
-#include "xml-writer.hh"
+#include "value-to-json.hh"
#include "eval-inline.hh"
#include "util.hh"
@@ -9,7 +8,7 @@
namespace nix {
-static void escapeJSON(std::ostream & str, const string & s)
+void escapeJSON(std::ostream & str, const string & s)
{
str << "\"";
foreach (string::const_iterator, i, s)
@@ -55,32 +54,26 @@ void printValueAsJSON(EvalState & state, bool strict,
case tAttrs: {
Bindings::iterator i = v.attrs->find(state.sOutPath);
if (i == v.attrs->end()) {
- str << "{";
+ JSONObject json(str);
StringSet names;
foreach (Bindings::iterator, i, *v.attrs)
names.insert(i->name);
- bool first = true;
foreach (StringSet::iterator, i, names) {
- if (!first) str << ","; else first = false;
Attr & a(*v.attrs->find(state.symbols.create(*i)));
- escapeJSON(str, *i);
- str << ":";
+ json.attr(*i);
printValueAsJSON(state, strict, *a.value, str, context);
}
- str << "}";
} else
printValueAsJSON(state, strict, *i->value, str, context);
break;
}
case tList: {
- str << "[";
- bool first = true;
+ JSONList json(str);
for (unsigned int n = 0; n < v.list.length; ++n) {
- if (!first) str << ","; else first = false;
+ json.elem();
printValueAsJSON(state, strict, *v.list.elems[n], str, context);
}
- str << "]";
break;
}