A TypeScript implementation of jq query language for JSON
For TypeScript:
import jq from 'jqts';
const pattern = jq.compile('[.[].x]');
pattern.evaluate([{ x: 1, x: 2 }]); // [1, 2]
For JavaScript:
const jq = require('jqts').default;
const pattern = jq.compile('[.[].x]');
pattern.evaluate([{ x: 1, x: 2 }]); // [1, 2]
| Filter |
Notation |
Status |
| Identity |
. |
✔️ |
| Object Identifier-Index |
.foo .foo.bar |
✔️ |
| Optional Object Identifier-Index |
.foo? |
✔️ |
| Generic Object Index |
.[<string>] |
✔️ |
| Array Index |
.[2] |
✔️ |
| Array/String Slice |
.[10:15] |
✔️ |
| Array/Object Value Iterator |
.[] .[]? |
✔️ |
| Comma |
.foo, .bar |
✔️ |
| Pipe |
.[] | .foo |
✔️ |
| Parenthesis |
(. + 2) * 5 |
✔️ |
| JSON datatypes |
|
✔️ |
| Array Construction |
[.foo, .bar] |
✔️ |
| Object Construction |
{foo:.bar} {baz} |
✔️ |
| Recursive Descent |
.. |
|
| Addition |
+ |
✔️ |
| Subtraction |
- |
✔️ |
| Multiplication,Division,Modulo |
* / % |
✔️ |
length |
length |
✔️ |
utf8bytelength |
utf8bytelength |
✔️ |
keys, keys_unsorted |
keys keys_unsorted |
✔️ |
has(key) |
has("foo") |
✔️ |
in |
in([0, 1]) |
✔️ |
map |
map |
✔️ |
map_values |
map_value |
|
path(path_expression) |
|
|
del(path_expression) |
|
|
getpath(PATHS) |
|
|
setpath(PATHS; VALUE) |
|
|
delpaths(PATHS) |
|
|
to_entries, from_entries |
|
✔️ |
with_entries |
|
|
select(boolean_expression) |
|
✔️ |
arrays, objects, iterables, booleans, numbers, normals, finites, strings, nulls, values, scalars |
|
✔️ |
empty |
|
✔️ |
error(message) |
|
✔️ |
halt |
|
|
halt_error, halt_error(exit_code) |
|
|
$__loc__ |
|
|
paths, paths(node_filter), leaf_paths |
|
|
add |
|
✔️ |
any |
|
✔️ |
any(condition), any(generator; condition) |
|
|
all |
|
✔️ |
all(condition), all(generator; condition) |
|
|
flatten, flatten(depth) |
|
✔️ |
range(upto), range(from;upto), range(from;upto;by) |
|
✔️ |
floor |
|
✔️ |
sqrt |
|
✔️ |
tonumber |
|
✔️ |
tostring |
|
✔️ |
type |
|
✔️ |
infinite, nan, isinfinite, isnan, isfinite, isnormal |
|
✔️ |
sort, sort_by(path_expression) |
|
✔️ |
group_by(path_expression) |
|
✔️ |
min, max, min_by(path_exp), max_by(path_exp) |
|
✔️ |
unique, unique_by(path_exp) |
|
✔️ |
reverse |
|
✔️ |
contains(element) |
|
✔️ |
indices(s) |
|
✔️ |
index(s), rindex(s) |
|
✔️ |
inside |
|
✔️ |
startswith(str) |
|
✔️ |
endswith(str) |
|
✔️ |
combinations, combinations(n) |
|
✔️ |
ltrimstr(str) |
|
|
rtrimstr(str) |
|
|
explode |
|
|
implode |
|
|
split(str) |
|
|
join(str) |
|
|
ascii_downcase, ascii_upcase |
|
|
while(cond; update) |
|
|
until(cond; next) |
|
|
recurse(f), recurse, recurse(f; condition), recurse_down |
|
|
walk(f) |
|
|
$ENV, env |
|
|
transpose |
|
|
bsearch(x) |
|
|
String interpolation - \(foo) |
|
|
| Convert to/from JSON |
|
|
| Format strings and escaping |
|
|
| Dates |
|
|
| SQL-Style Operators |
|
|
| builtins |
|
|
==, != |
|
|
| if-then-else |
|
|
>, >=, <=, < |
|
|
| and/or/not |
and, or, not |
|
| Alternative operator |
// |
✔️ |
| try-catch |
|
|
| Breaking out of control structures |
|
|
| Error Suppression / Optional Operator |
? |
|
| Regular expressions (PCRE) |
|
|
| Variable / Symbolic Binding Operator |
|
|
| Destructuring Alternative Operator |
|
|
| Defining Functions |
|
|
| Scoping |
|
|
| Reduce |
|
|
| Recursion |
|
|
| Generators and Iterators |
|
|
| Math |
|
|
| I/O |
|
|
| Streaming |
|
|
| Assignment |
|
|
| Modules |
|
|
| Colors |
|
|
MIT