Added flatten and flatten(x) functions

Fix #415.
This commit is contained in:
Santiago Lapresta authored and Nicolas Williams committed 2014-06-16 17:03:05 -05:00
1 parent f741074267
commit 061a604a2a
3 files changed
+36

No files matched your search

+2
View File
@@ -724,6 +724,8 @@ static const char* const jq_builtins[] = {
"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));",
"def flatten: reduce .[] as $i ([]; if $i | type == \"array\" then . + ($i | flatten) else . + [$i] end);",
"def flatten(x): reduce .[] as $i ([]; if $i | type == \"array\" and x > 0 then . + ($i | flatten(x-1)) else . + [$i] end);",
};
#undef LIBM_DD