]> granicus.if.org Git - jq/commitdiff
Added `join` function
authorSantiago Lapresta <santiago.lapresta@gmail.com>
Thu, 29 May 2014 22:45:16 +0000 (00:45 +0200)
committerNicolas Williams <nico@cryptonector.com>
Sun, 8 Jun 2014 02:53:03 +0000 (21:53 -0500)
Signed-off-by: Nicolas Williams <nico@cryptonector.com>
builtin.c
docs/content/3.manual/manual.yml

index 83d28decf49ce6373536a0d72d8a1764a94992be..ad4145a5035c58f6d0f8fb810eab0ab96c2d1364 100644 (file)
--- a/builtin.c
+++ b/builtin.c
@@ -703,6 +703,7 @@ static const char* const jq_builtins[] = {
   "def nulls: select(type == \"null\");",
   "def values: arrays, objects, booleans, numbers, strings;",
   "def scalars: select(. == null or . == true or . == false or type == \"number\" or type == \"string\");",
+  "def join(x): reduce .[] as $i (\"\"; . + (if . == \"\" then $i else x + $i end));",
 };
 #undef LIBM_DD
 
index 801b4b2121da4332fb131a7015e1a2f60c23aab9..e64de245f0f14fb5316b47a58bf5a4a9354b8926 100644 (file)
@@ -1075,6 +1075,20 @@ sections:
             input: '"a, b,c,d, e"'
             output: ['["a","b,c,d","e"]']
 
+      - title: `join`
+        body: |
+        
+          Joins the array of elements given as input, using the
+          argument as separator. It is the inverse of `split`: that is,
+          running `split("foo") | join("foo")` over any input string
+          returns said input string.
+          
+        examples:
+          - program: 'join(", ")'
+            input: '["a","b,c,d","e"]'
+            output: ['"a, b,c,d, e"']
+
+
       - title: `recurse`
         body: |