0.0.27 • Published 6 months ago
jsjq v0.0.27
jsjq - jq with ECMAScript syntax
it uses eval() to run your code, be warned (code is checked and run using safe-eval)
Usage with npx:
npx jsjq '.data.map(x => x*2)' '{"data": [1, 2, 3]}'
# output: [2, 4, 6]
Normal usage:
npm i -g jsjq
# from JSON string
jsjq '.data.map(x => x*2)' '{"data": [1, 2, 3]}'
# from JSON file
jsjq '.data.map(x => x*2)' example.json
Pipe usage:
echo '{"data": [1, 2, 3]}' | jsjq '.data.map(x => x*2)'
Custom object methods (may be overridden by properties with the same name):
jsjq '.data.listKeys()' '{ "data": {"a": 1, "b": 2, "c": 3} }'
# output: [ 'a', 'b', 'c' ]
jsjq '.data.listValues()' '{ "data": {"a": 1, "b": 2, "c": 3} }'
# output: [ 1, 2, 3 ]
jsjq '.data.listEntries()' '{ "data": {"a": 1, "b": 2, "c": 3} }'
# output: [ [ 'a', 1 ], [ 'b', 2 ], [ 'c', 3 ] ]
jsjq '.data.stringify()' '{ "data": {"a": 1, "b": 2, "c": 3} }'
# output: '{"a":1,"b":2,"c":3}'
# override:
jsjq '.data.stringify()' '{ "stringify": 123 }'
# will throw an error
Custom array methods:
jsjq '.data.compact()' '{ "data": [1, 2, 2, 3] }'
# output: [ 1, 2, 3 ]
jsjq '.data.stringify()' '{ "data": [1, 2, 2, 3] }'
# output '[1,2,2,3]'
Options:
- -c, --compact-output compact instead of pretty-printed output;
- -r, --raw-output output strings without escapes and quotes;
- -i, --interactive run jsjq in interactive mode (experimental)
- -t, --type print the type of the value instead of the value itself;
- -v, --version show the version;
- -h, --help show the help;
Code check:
jsjq '.data; process.exit(1)' '{}'
# will throw an error
0.0.25
6 months ago
0.0.26
6 months ago
0.0.27
6 months ago
0.0.23
2 years ago
0.0.20
2 years ago
0.0.21
2 years ago
0.0.22
2 years ago
0.0.19
2 years ago
0.0.10
2 years ago
0.0.11
2 years ago
0.0.12
2 years ago
0.0.13
2 years ago
0.0.14
2 years ago
0.0.3
2 years ago
0.0.15
2 years ago
0.0.9
2 years ago
0.0.16
2 years ago
0.0.8
2 years ago
0.0.17
2 years ago
0.0.18
2 years ago
0.0.5
2 years ago
0.0.4
2 years ago
0.0.7
2 years ago
0.0.6
2 years ago
0.0.2
2 years ago
0.0.1
2 years ago