A TypeScript implementation of `jq` query language for JSON
npm install jqtsA TypeScript implementation of jq query language for JSON
``sh`
npm install jqts
For TypeScript:
`typescript
import jq from 'jqts';
const pattern = jq.compile('[.[].x]');
pattern.evaluate([{ x: 1, x: 2 }]); // [1, 2]
`
For JavaScript:
`javascript
const jq = require('jqts').default;
const pattern = jq.compile('[.[].x]');
pattern.evaluate([{ x: 1, x: 2 }]); // [1, 2]
`
| Filter | Notation | Status |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------- | ------------------ |
| Identity | . | :heavy_check_mark: |.foo
| Object Identifier-Index | .foo.bar | :heavy_check_mark: |.foo?
| Optional Object Identifier-Index | | :heavy_check_mark: |.[
| Generic Object Index | | :heavy_check_mark: |.[2]
| Array Index | | :heavy_check_mark: |.[10:15]
| Array/String Slice | | :heavy_check_mark: |.[]
| Array/Object Value Iterator | .[]? | :heavy_check_mark: |.foo, .bar
| Comma | | :heavy_check_mark: |.[] \| .foo
| Pipe | | :heavy_check_mark: |(. + 2) * 5
| Parenthesis | | :heavy_check_mark: |[.foo, .bar]
| JSON datatypes | | :heavy_check_mark: |
| Array Construction | | :heavy_check_mark: |{foo:.bar}
| Object Construction | {baz} | :heavy_check_mark: |..
| Recursive Descent | | |+
| Addition | | :heavy_check_mark: |-
| Subtraction | | :heavy_check_mark: |
| Multiplication,Division,Modulo | / % | :heavy_check_mark: |length
| | length | :heavy_check_mark: |utf8bytelength
| | utf8bytelength | :heavy_check_mark: |keys
| , keys_unsorted | keys keys_unsorted | :heavy_check_mark: |has(key)
| >) | has("foo") | :heavy_check_mark: |in
| | in([0, 1]) | :heavy_check_mark: |map
| ,map_values(x)>) | map | :heavy_check_mark: |map_values
| ,map_values(x)>) | map_value | |path(path_expression)
| >) | | |del(path_expression)
| >) | | |getpath(PATHS)
| >) | | |setpath(PATHS; VALUE)
| >) | | |delpaths(PATHS)
| >) | | |to_entries, from_entries
| | | :heavy_check_mark: |with_entries
| | | |select(boolean_expression)
| >) | | :heavy_check_mark: |arrays
| , objects, iterables, booleans, numbers, normals, finites, strings, nulls, values, scalars | | :heavy_check_mark: |empty
| | | :heavy_check_mark: |error(message)
| >) | | :heavy_check_mark: |halt
| | | |halt_error
| , halt_error(exit_code)>) | | |$__loc__
| |paths
| , paths(node_filter), leaf_paths,leaf_paths>) | | |add
| | | :heavy_check_mark: |any
| ,any(generator;condition)>) | | :heavy_check_mark: |any(condition)
| , any(generator; condition),any(generator;condition)>) | | |all
| ,all(generator;condition)>) | | :heavy_check_mark: |all(condition)
| , all(generator; condition),all(generator;condition)>) | | |flatten
| , flatten(depth)>) | | :heavy_check_mark: |range(upto)
| , range(from;upto), range(from;upto;by),range(from;upto)range(from;upto;by)>) | | :heavy_check_mark: |floor
| | | :heavy_check_mark: |sqrt
| | | :heavy_check_mark: |tonumber
| | | :heavy_check_mark: |tostring
| | | :heavy_check_mark: |type
| | | :heavy_check_mark: |infinite, nan, isinfinite, isnan, isfinite, isnormal
| | | :heavy_check_mark: |sort, sort_by(path_expression)
| >) | | :heavy_check_mark: |group_by(path_expression)
| >) | | :heavy_check_mark: |min
| , max, min_by(path_exp), max_by(path_exp),max_by(path_exp)>) | | :heavy_check_mark: |unique, unique_by(path_exp)
| >) | | :heavy_check_mark: |reverse
| | | :heavy_check_mark: |contains(element)
| >) | | :heavy_check_mark: |indices(s)
| >) | | :heavy_check_mark: |index(s), rindex(s)
| ,rindex(s)>) | | :heavy_check_mark: |inside
| | | :heavy_check_mark: |startswith(str)
| >) | | :heavy_check_mark: |endswith(str)
| >) | | :heavy_check_mark: |combinations, combinations(n)
| >) | | :heavy_check_mark: |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)
| | | |\(foo)
| String interpolation - | | |==
| Convert to/from JSON | | |
| Format strings and escaping | | |
| Dates | | |
| SQL-Style Operators | | |
| builtins | | |
| , != | | |>
| if-then-else | | |
| , >=, <=, < | | |and
| and/or/not | , or, not | |//
| Alternative operator | | :heavy_check_mark: |?` | |
| 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