about summary refs log tree commit diff
path: root/src/libexpr/value-to-json.cc
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2014-09-29T22·41+0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2014-09-29T22·41+0200
commitd61853430a3df8914995ae35ac7a0795827d7a87 (patch)
treecf84b255979112cd4cbf8672578c49e78d23ab64 /src/libexpr/value-to-json.cc
parentf77be20c16621a8e6b91f95cad9711b87d113485 (diff)
Support control characters in JSON output
Diffstat (limited to 'src/libexpr/value-to-json.cc')
-rw-r--r--src/libexpr/value-to-json.cc3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/libexpr/value-to-json.cc b/src/libexpr/value-to-json.cc
index a2004df5c8c5..d1ec9b566d66 100644
--- a/src/libexpr/value-to-json.cc
+++ b/src/libexpr/value-to-json.cc
@@ -3,6 +3,7 @@
 #include "util.hh"
 
 #include <cstdlib>
+#include <iomanip>
 
 
 namespace nix {
@@ -16,6 +17,8 @@ void escapeJSON(std::ostream & str, const string & s)
         else if (*i == '\n') str << "\\n";
         else if (*i == '\r') str << "\\r";
         else if (*i == '\t') str << "\\t";
+        else if (*i >= 0 && *i < 32)
+            str << "\\u" << std::setfill('0') << std::setw(4) << std::hex << (uint16_t) *i << std::dec;
         else str << *i;
     str << "\"";
 }