diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2014-07-04T11·34+0200 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2014-07-04T11·34+0200 |
commit | beaf3e90aff14664b98f2c7ab7387c9fa4354fd1 (patch) | |
tree | cc1bab6524c7e616697efbae788e4b997a3213c4 /src/libexpr/primops.cc | |
parent | e82951fe23daa961ef18b0c5cc9ba1f5d8906186 (diff) |
Add builtin function ‘fromJSON’
Fixes #294.
Diffstat (limited to 'src/libexpr/primops.cc')
-rw-r--r-- | src/libexpr/primops.cc | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index ff82f36b52f7..01c7ca444119 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -6,6 +6,7 @@ #include "archive.hh" #include "value-to-xml.hh" #include "value-to-json.hh" +#include "json-to-value.hh" #include "names.hh" #include "eval-inline.hh" @@ -775,6 +776,14 @@ static void prim_toJSON(EvalState & state, const Pos & pos, Value * * args, Valu } +/* Parse a JSON string to a value. */ +static void prim_fromJSON(EvalState & state, const Pos & pos, Value * * args, Value & v) +{ + string s = state.forceStringNoCtx(*args[0], pos); + parseJSON(state, s, v); +} + + /* Store a string in the Nix store as a source file that can be used as an input by derivations. */ static void prim_toFile(EvalState & state, const Pos & pos, Value * * args, Value & v) @@ -1396,6 +1405,7 @@ void EvalState::createBaseEnv() // Creating files addPrimOp("__toXML", 1, prim_toXML); addPrimOp("__toJSON", 1, prim_toJSON); + addPrimOp("__fromJSON", 1, prim_fromJSON); addPrimOp("__toFile", 2, prim_toFile); addPrimOp("__filterSource", 2, prim_filterSource); |