]> granicus.if.org Git - jq/commitdiff
Define `map_values` 628/head
authorSantiago Lapresta <santiago.lapresta@gmail.com>
Mon, 22 Dec 2014 22:05:35 +0000 (23:05 +0100)
committerSantiago Lapresta <santiago.lapresta@gmail.com>
Mon, 22 Dec 2014 22:05:35 +0000 (23:05 +0100)
builtin.c
docs/content/3.manual/manual.yml

index dc355353f274a531c28d0a2216ca7b68920862b6..b94ca5862934c9c62480788c68a5f21ebd72c7d7 100644 (file)
--- a/builtin.c
+++ b/builtin.c
@@ -950,6 +950,7 @@ static block bind_bytecoded_builtins(block b) {
 static const char* const jq_builtins[] = {
   "def break: error(\"break\");",
   "def map(f): [.[] | f];",
+  "def map_values(f): .[] |= f;",
   "def select(f): if f then . else empty end;",
   "def sort_by(f): _sort_by_impl(map([f]));",
   "def group_by(f): _group_by_impl(map([f]));",
index 42c6c98ce2edfeaba8a8dca068b115e217ddb610..7002b47a0d769202c3f5cc1e02ebc4c672a1166d 100644 (file)
@@ -777,20 +777,27 @@ sections:
           null and objects would, but with the given message as the
           error's value.
 
-      - title: "`map(x)`"
+      - title: "`map(x)`, `map_values(x)`"
         body: |
 
           For any filter `x`, `map(x)` will run that filter for each
           element of the input array, and produce the outputs a new
           array. `map(.+1)` will increment each element of an array of numbers.
-
+          
+          Similarly, `map_values(x)` will run that filter for each element,
+          but it will return an object when an object is passed.
+          
           `map(x)` is equivalent to `[.[] | x]`. In fact, this is how
-          it's defined.
+          it's defined. Similarly, `map_values(x)` is defined as `.[] |= x`.
 
         examples:
           - program: 'map(.+1)'
             input: '[1,2,3]'
             output: ['[2,3,4]']
+          
+          - program: 'map_values(.+1)'
+            input: '{"a": 1, "b": 2, "c": 3}'
+            output: ['{"a": 2, "b": 3, "c": 4}']
 
       - title: "`paths`, `paths(node_filter)`, `leaf_paths`"
         body: |