Skip to content

Instantly share code, notes, and snippets.

@mamemomonga
Created August 16, 2020 16:30
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 mamemomonga/becc4702fd2e89a3f55b70b5d11c77b2 to your computer and use it in GitHub Desktop.
Save mamemomonga/becc4702fd2e89a3f55b70b5d11c77b2 to your computer and use it in GitHub Desktop.
jqをつかったソート

hoge.jsonの内容を整形

$ cat hoge.json | jq .
[
  {
    "id": 2,
    "name": "ゆかり"
  },
  {
    "id": 3,
    "name": "ゆい"
  },
  {
    "id": 1,
    "name": "ゆずこ"
  }
]

idの値でソート

$  cat hoge.json | jq 'sort_by(.id)'
[
  {
    "id": 1,
    "name": "ゆずこ"
  },
  {
    "id": 2,
    "name": "ゆかり"
  },
  {
    "id": 3,
    "name": "ゆい"
  }
]

参考

jq で連続する JSON を特定のキーでソートする https://qiita.com/yuya_takeyama/items/6ebddc62f21b7d01c662

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment