net.thisptr.jackson.jq.jq.json Maven / Gradle / Ivy
# Most of the function definitions in this file originate from builtin.jq(*1)
# in the official jq repository.
#
# 1) https://github.com/stedolan/jq/blob/master/src/builtin.jq)
#
# jq is copyright (C) 2012 Stephen Dolan
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
{
"functions": [
{"name": "@text", "body": "tostring"},
{"name": "@json", "body": "tojson"},
{"name": "paths", "args": [], "body": "paths(. != null)"},
{"name": "arrays", "args": [], "body": "select(type == \"array\")"},
{"name": "booleans", "args": [], "body": "select(type == \"boolean\")"},
{"name": "del", "args": ["f"], "body": "delpaths([path(f)])"},
{"name": "nulls", "args": [], "body": "select(type == \"null\")"},
{"name": "objects", "args": [], "body": "select(type == \"object\")"},
{"name": "numbers", "args": [], "body": "select(type == \"number\")"},
{"name": "strings", "args": [], "body": "select(type == \"string\")"},
{"name": "finites", "args": [], "body": "select(isfinite)"},
{"name": "normals", "args": [], "body": "select(isnormal)"},
{"name": "values", "args": [], "body": "booleans, numbers, strings, arrays, objects"},
{"name": "iterables", "args": [], "body": "arrays, objects"},
{"name": "scalars", "args": [], "body": "nulls, booleans, numbers, strings"},
{"name": "isfinite", "args": [], "body": "type == \"number\" and (isinfinite | not)"},
{"name": "add", "args": [], "body": "reduce .[] as $item (null; . + $item)"},
{"name": "min", "args": [], "body": "min_by(.)"},
{"name": "max", "args": [], "body": "max_by(.)"},
{"name": "sort", "args": [], "body": "sort_by(.)"},
{"name": "unique", "args": [], "body": "group_by(.) | map(.[0])"},
{"name": "unique_by", "args": ["f"], "body": "group_by(f) | map(.[0])"},
{"name": "with_entries", "args": ["f"], "body": "to_entries | map(f) | from_entries"},
{"name": "select", "args": ["pred"], "body": "if pred then . else empty end"},
{"name": "map", "args": ["f"], "body": "[.[] | f]"},
{"name": "recurse", "args": ["f"], "body": "def r: ., (f | select(. != null) | r); r"},
{"name": "recurse", "args": ["f", "cond"], "body": "def r: ., (f | select(cond) | r); r"},
{"name": "recurse", "args": [], "body": "recurse(.[]?)"},
{"name": "recurse_down", "args": [], "body": "recurse"},
{"name": "last", "args": [], "body": ".[-1]"},
{"name": "last", "args": ["stream"], "body": "reduce stream as $i (null; $i)"},
{"name": "first", "args": [], "body": ".[0]"},
{"name": "first", "args": ["g"], "body": "label $out | foreach g as $item ([false, null]; if .[0]==true then break $out else [true, $item] end; .[1])", "version": "[, 1.6)"},
{"name": "first", "args": ["g"], "body": "label $out | g | ., break $out", "version": "[1.6, )"},
{"name": "nth", "args": ["n"], "body": "n as $n | .[$n]"},
{"name": "transpose", "body": "if . == [] then [] else . as $in | (map(length) | max) as $max | length as $length | reduce range(0; $max) as $j ([]; . + [reduce range(0; $length) as $i ([]; . + [$in[$i][$j]])]) end"},
{"name": "limit", "args": ["$n", "exp"], "body": "if $n < 0 then exp else label $out | foreach exp as $item ([$n, null]; if .[0] < 1 then break $out else [.[0] -1, $item] end; .[1]) end"},
{"name": "nth", "args": ["n", "g"], "body": "n as $n | if $n < 0 then error(\"nth doesn't support negative indices\") else last(limit($n + 1; g)) end"},
{"name": "any", "args": ["generator", "condition"], "body": "[label $out | foreach generator as $i (false; if . then break $out elif $i | condition then true else . end; if . then . else empty end)] | length == 1"},
{"name": "any", "args": ["condition"], "body": "any(.[]; condition)"},
{"name": "any", "args": [], "body": "any(.)"},
{"name": "all", "args": ["generator", "condition"], "body": "[label $out | foreach generator as $i (true; if .|not then break $out elif $i | condition then . else false end; if .|not then . else empty end)] | length == 0"},
{"name": "all", "args": ["condition"], "body": "all(.[]; condition)"},
{"name": "all", "args": [], "body": "all(.)"},
{"name": "flatten", "args": [], "body": "_flatten(-1)"},
{"name": "flatten", "args": ["$x"], "body": "if $x < 0 then error(\"flatten depth must not be negative\") else _flatten($x) end"},
{"name": "_flatten", "args": ["$x"], "body": "reduce .[] as $i ([]; if $i | type == \"array\" and $x != 0 then . + ($i | _flatten($x-1)) else . + [$i] end)"},
{"name": "match", "args": ["re", "mode"], "body": "_match_impl(re; mode; false)|.[]"},
{"name": "match", "args": ["$val"], "body": "($val|type) as $vt | if $vt == \"string\" then match($val; null) elif $vt == \"array\" and ($val | length) > 1 then match($val[0]; $val[1]) elif $vt == \"array\" and ($val | length) > 0 then match($val[0]; null) else error( $vt + \" not a string or array\") end"},
{"name": "test", "args": ["re", "mode"], "body": "_match_impl(re; mode; true)"},
{"name": "test", "args": ["$val"], "body": "($val|type) as $vt | if $vt == \"string\" then test($val; null) elif $vt == \"array\" and ($val | length) > 1 then test($val[0]; $val[1]) elif $vt == \"array\" and ($val | length) > 0 then test($val[0]; null) else error( $vt + \" not a string or array\") end"},
{"name": "capture", "args": ["re", "mods"], "body": "match(re; mods) | reduce ( .captures | .[] | select(.name != null) | { (.name) : .string } ) as $pair ({}; . + $pair)"},
{"name": "capture", "args": ["$val"], "body": "($val|type) as $vt | if $vt == \"string\" then capture($val; null) elif $vt == \"array\" and ($val | length) > 1 then capture($val[0]; $val[1]) elif $vt == \"array\" and ($val | length) > 0 then capture($val[0]; null) else error( $vt + \" not a string or array\") end"},
{"name": "scan", "args": ["re"], "body": "scan(re; \"\")"},
{"name": "scan", "args": ["re", "flags"], "body": "match(re; flags + \"g\") | if (.captures|length > 0) then [ .captures | .[] | .string ] else .string end"},
{"name": "_nwise", "args": ["a", "$n"], "body": "if a|length <= $n then a else a[0:$n] , _nwise(a[$n:]; $n) end"},
{"name": "_nwise", "args": ["$n"], "body": "_nwise(.; $n)"},
{"name": "splits", "args": ["$re", "flags"], "body": ". as $s | [ match($re; \"g\" + flags) | (.offset, .offset + .length) ] | [0] + . +[$s|length] | _nwise(2) | $s[.[0]:.[1] ]"},
{"name": "splits", "args": ["$re"], "body": "splits($re; null)"},
{"name": "split", "args": ["$re", "flags"], "body": "[splits($re; flags)]"},
{"name": "sub", "args": ["$re", "s"], "body": "_sub_impl($re; s; \"\")"},
{"name": "sub", "args": ["$re", "s", "flags"], "body": "_sub_impl($re; s; flags)"},
{"name": "gsub", "args": ["$re", "s", "flags"], "body": "_sub_impl($re; s; flags + \"g\")"},
{"name": "gsub", "args": ["$re", "s"], "body": "_sub_impl($re; s; \"g\")"},
{"name": "ascii_downcase", "body": "explode | map( if 65 <= . and . <= 90 then . + 32 else . end) | implode"},
{"name": "ascii_upcase", "body": "explode | map( if 97 <= . and . <= 122 then . - 32 else . end) | implode"},
{"name": "until", "args": ["cond", "next"], "body": "def _until: if cond then . else (next|_until) end; _until"},
{"name": "while", "args": ["cond", "update"], "body": "def _while: if cond then ., (update | _while) else empty end; _while"},
{"name": "leaf_paths", "args": [], "body": "paths(scalars)"},
{"name": "walk", "args": ["f"], "body": ". as $in | if type == \"object\" then reduce keys[] as $key ( {}; . + { ($key): ($in[$key] | walk(f)) } ) | f elif type == \"array\" then map( walk(f) ) | f else f end", "version": "[1.6, )"},
{"name": "in", "args": ["xs"], "body": ". as $x | xs | has($x)"},
{"name": "inside", "args": ["xs"], "body": ". as $x | xs | contains($x)"},
{"name": "combinations", "args": [], "body": "if length == 0 then [] else .[0][] as $x | (.[1:] | combinations) as $y | [$x] + $y end"},
{"name": "combinations", "args": ["n"], "body": ". as $dot | [range(n) | $dot] | combinations"},
{"name": "map_values", "args": ["f"], "body": ".[] |= f"},
{"name": "_modify", "args": ["paths", "update"], "body": "reduce path(paths) as $p (.; label $out | (setpath($p; getpath($p) | update) | ., break $out), delpaths([$p]))", "version": "[1.6, )"},
{"name": "_modify", "args": ["paths", "update"], "body": "reduce path(paths) as $p (.; setpath($p; getpath($p) | update))", "version": "[, 1.6)"}
]
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy