Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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