Create a notebook with power of jq filters and the power of jq playground extension
Open new file and change 'Language Mode' to jqpg
(JQ PlayGround) or
use a file with .jqpg
extension.
jq [options] <jq filter>
[ JSON_TEXT | STRINGS | URL | FILE | COMMAND_LINE ]
Command Palette... (ctrl + shift + p): jq playground: Examples
# Example 1
jq '.foo'
{"foo": 42, "bar": "less interesting data"}
# Example 2
jq '.foo'
{
"foo": 42,
"bar": "less interesting data"
}
# Example 1: raw input string
jq -R 'split(" ")'
non arcu risus quis varius quam quisque id diam vel
# Example 2
jq .[5:10]
"less interesting data"
# Example 1
jq '.[0] | {message: .commit.message, name: .commit.committer.name}'
https://api.github.com/repos/stedolan/jq/commits?per_page=5
# Example 1: relative pahts
jq '.foo,.bar'
../files/example.json
# Example 2: absolute pahts
jq '.foo,.bar'
/home/dev/files/example.json
# Example 3: buffer file
jq '.'
Untitled-1
# Example 4: workspace file
jq '.'
opened-workspace-file-with-data.json
# Example 5 (Multifile)
jq '{
(input_filename|rtrimstr(".json")) :
.scripts | keys | map(select(. | contains("test"))) }'
/home/dev/client/package.json /home/dev/server/package.json
# Example 1
jq '.token'
$ curl -X GET "http://httpbin.org/bearer" -H "accept: application/json" -H "Authorization: Bearer 1234"
# Example 2
jq -R -s 'split("\n") | .[] | { file: ., lenght: . | length}'
$ ls /etc/
TOKEN = 1234
ENDPOINT = bearer
# Example 1
jq '.token'
$ curl -X GET "http://httpbin.org/$ENDPOINT" -H "accept: application/json" -H "Authorization: Bearer $TOKEN"
# Example 2
jq -R -s 'split("\n") | .[] | { file: ., lenght: . | length}'
$ ls $HOME
# Example 1
jq -r '(map(keys)
| add
| unique) as $cols
| map(. as $row
| $cols
| map($row[.])) as $rows
| $cols, $rows[]
| @csv'
[
{"code": "NSW", "name": "New South Wales", "level":"state", "country": "AU"},
{"code": "AB", "name": "Alberta", "level":"province", "country": "CA"},
{"code": "ABD", "name": "Aberdeenshire", "level":"council area", "country": "GB"},
{"code": "AK", "name": "Alaska", "level":"state", "country": "US"}
]
# Exampmle 2
jq 'if . == 0 then
"zero"
elif . == 1 then
"one"
else
"many"
end
'
2
# Example 1
jq --slurp '. + [5] + [6]'
[
1,
2,
3
]
# Example 2
jq --arg var val '.value = $var'
{}
# Example 3
jq --raw-input --slurp 'split("\\n")'
foo\nbar\nbaz
# Example 4
jq -r '(map(keys) | add | unique) as $cols | map(. as $row | $cols | map($row[.])) as $rows | $cols, $rows[] | @csv'
[
{"code": "NSW", "name": "New South Wales", "level":"state", "country": "AU"},
{"code": "AB", "name": "Alberta", "level":"province", "country": "CA"},
{"code": "ABD", "name": "Aberdeenshire", "level":"council area", "country": "GB"},
{"code": "AK", "name": "Alaska", "level":"state", "country": "US"}
]
# Example 5
jq --raw-output '"\(.one)\t\(.two)"'
{"one":1,"two":"x"}
# Opened workspace file as filter
jq opened-workspace-file-filter.jq
[1, 2, 3, 4, 5]
# Opened workspace file as filter and query input
jq opened-workspace-file-filter.jq
opened-workspace-file-with-data.json
jq '[.[].url]'
> tmp.json
$ curl 'https://api.github.com/repos/stedolan/jq/commits?per_page=5'
http|curl|wget|cat|echo|ls|dir|grep|tail|head|find
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "jq test",
"type": "shell",
"command": "curl",
"args": ["-v", "${input:urls}\\¶m=${input:param}"],
"problemMatcher": []
}
],
"inputs": [
{
"id": "urls",
"type": "command",
"command": "extension.executeJqInputCommand",
"args": {
"filter": ".[3]",
"input": "/home/david/dev/tmp/jqpg-examples/tmp.json"
}
},
{
"id": "param",
"type": "command",
"command": "extension.executeJqInputCommand",
"args": {
"filter": ".[2]",
"input": "[10, 50, 100]",
"jsonInput": true
}
}
]
}
ctrl+shift+p → > Manual
ctrl+shift+p → > Tutorial
Thanks for cwd module patching 💻 Joseph Andersen
Thanks for updating deps and binary 💻 Yoz Grahame
Thanks for input variable 💻 Jeff Mercado
Thanks for input variable 💻 Leonel Galán
I be inspired by vscode-jq