LoginSignup
0
1

More than 3 years have passed since last update.

jqの備忘録

Posted at

こういうJSONがあった場合

item.json
{
  "items": [
    {
      "id": 1,
      "name": "Item1",
      "price": 1500
    },
    {
      "id": 2,
      "name": "Item1",
      "price": 1500
    }
  ]
}

idとnameだけ出したいとき

$ cat item.json | jq '.items | .[] | [.id, .name]'
[
  1,
  "Item1"
]
[
  2,
  "Item1"
]

こんなJSONの場合は

item.json
[
  {
    "id": 1,
    "name": "Item1",
    "price": 1500
  },
  {
    "id": 2,
    "name": "Item1",
    "price": 1500
  }
]

$ cat item.json | jq '.[] | [.id, .name]'
[
  1,
  "Item1"
]
[
  2,
  "Item1"
]
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1