jq
Linuxで利用可能なコマンド
JSONデータを処理する
変換
加工
生成
など
code:sample.json
{
"name": "Example Project",
"version": "1.2.3",
"description": "A sample JSON for jq testing.",
"license": "MIT",
"author": {
"name": "Taro Yamada",
"email": "taro.yamada@example.com"
},
"dependencies": [
{
"name": "library-a",
"version": "1.0.0",
"optional": false
},
{
"name": "library-b",
"version": "2.1.5",
"optional": true
},
{
"name": "library-c",
"version": "0.5.0",
"optional": false
}
],
"enabled": true,
"config": null
}
以下のように使える
code:sample
asebi@localhost ~$ jq .name sample.json
"Example Project"
asebi@localhost ~$ jq .author.name sample.json
"Taro Yamada"
asebi@localhost ~$ jq .dependencies sample.json
[
{
"name": "library-a",
"version": "1.0.0",
"optional": false
},
{
"name": "library-b",
"version": "2.1.5",
"optional": true
},
{
"name": "library-c",
"version": "0.5.0",
"optional": false
}
]
asebi@localhost ~$ jq .dependencies[] sample.json
{
"name": "library-a",
"version": "1.0.0",
"optional": false
}
{
"name": "library-b",
"version": "2.1.5",
"optional": true
}
{
"name": "library-c",
"version": "0.5.0",
"optional": false
}
asebi@localhost ~$
asebi@localhost ~$ jq .dependencies0 sample.json
{
"name": "library-a",
"version": "1.0.0",
"optional": false
}
asebi@localhost ~$
asebi@localhost ~$ jq .dependencies0.name sample.json
"library-a"
複数の項目を同時に取得もできる
code:sample
asebi@localhost ~$ jq -r '.name, .description | join(", ")' sample.json
Example Project, A sample JSON for jq testing.
#command #linux #json