]> granicus.if.org Git - jq/commitdiff
#285 add and builtins
authorNicolas Williams <nico@cryptonector.com>
Wed, 5 Feb 2014 21:23:32 +0000 (15:23 -0600)
committerNicolas Williams <nico@cryptonector.com>
Wed, 5 Feb 2014 21:23:32 +0000 (15:23 -0600)
builtin.c

index 087741faacdfc4712377be67489cd7597383fe77..f5c48a6adc05f8a9d8a1a6c3b160a83f5006195b 100644 (file)
--- a/builtin.c
+++ b/builtin.c
@@ -678,6 +678,8 @@ static const char* const jq_builtins[] = {
   "def reverse: [.[length - 1 - range(0;length)]];",
   "def index(i): .[i][0];",
   "def rindex(i): .[i][-1:][0];",
+  "def paths: path(recurse(if (type|. == \"array\" or . == \"object\") then .[] else empty end))|select(length > 0);",
+  "def leaf_paths: . as $dot|paths|select(. as $p|$dot|getpath($p)|type|. == \"array\" or . == \"object\");",
 };