summaryrefslogtreecommitdiffstats
path: root/builtin.c
diff options
context:
space:
mode:
authorStephen Dolan <mu@netsoc.tcd.ie>2013-05-13 16:15:49 +0100
committerStephen Dolan <mu@netsoc.tcd.ie>2013-05-13 16:15:49 +0100
commita625d2821ecb27b87266762545f88d7d4aa59d31 (patch)
tree82fb4a6e7920673fa7a2570178f22cc47dc07d37 /builtin.c
parentd8706fd4607ee1b5b56debd4da39e3314739f126 (diff)
Add to_entries, from_entries and with_entries functions.
Closes #97.
Diffstat (limited to 'builtin.c')
-rw-r--r--builtin.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/builtin.c b/builtin.c
index 1516c6c6..2a48ba35 100644
--- a/builtin.c
+++ b/builtin.c
@@ -547,6 +547,9 @@ static const char* const jq_builtins[] = {
"def _assign(paths; value): value as $v | fold . as $obj (path(paths) as $p | $obj | setpath($p; $v));",
"def _modify(paths; update): fold . as $obj (path(paths) as $p | $obj | setpath($p; getpath($p) | update));",
"def recurse(f): ., (f | select(. != null) | recurse(f));",
+ "def to_entries: [keys[] as $k | {key: $k, value: .[$k]}];",
+ "def from_entries: map({(.key): .value}) | add;",
+ "def with_entries(f): to_entries | map(f) | from_entries;",
};