Skip to content

Instantly share code, notes, and snippets.

@nojima
Last active September 20, 2017 01:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nojima/41ede970664724bfe61daa70a8c6b49e to your computer and use it in GitHub Desktop.
Save nojima/41ede970664724bfe61daa70a8c6b49e to your computer and use it in GitHub Desktop.

jq レシピ集

JSON オブジェクトの特定のキーの値を出力する

. に続けて所望するキー名を書く。

例:

$ echo '{"foo": "hello", "bar": "world"}' | jq -r '.foo'
hello

JSON array を改行区切りテキストとして出力する

jq -r '.[]'

例:

$ echo '["hello", "json", "world"]' | jq -r '.[]'
hello
json
world

JSON オブジェクトの特定のキーの値を変更する

= オペレータを使う。

例:

echo '{"foo": false, "bar": false}' | jq '.foo = true'
{
  "foo": true,
  "bar": false
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment