Skip to content

Instantly share code, notes, and snippets.

@falgon
Created June 1, 2022 10:47
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 falgon/8d821db041fdacf5f89c4d6b5cbdf4fe to your computer and use it in GitHub Desktop.
Save falgon/8d821db041fdacf5f89c4d6b5cbdf4fe to your computer and use it in GitHub Desktop.

これが

{
  [
    "xxxxxx",
    "<0.12",
    "0.11.11",
    "hoge",
    "1",
    null,
    null
  ],
  [
    "xxxxxx",
    "<0.15.0",
    "0.11.11",
    "foo",
    "2",
    null,
    null
  ]
}

こうなる

[
  {
    "package": "xxxxxx",
    "vulnerabilities": [
      {
        "affected": "<0.12",
        "installed": "0.11.11",
        "description": "hoge",
        "id": "1"
      },
      {
        "affected": "<0.15.0",
        "installed": "0.11.11",
        "description": "foo",
        "id": "2"
      }
    ]
  }
]
cat requirements.txt |
safety check --json --stdin |
jq '. | sort_by(.[0]) | group_by(.[0]) | map( { "package": (.[0][0]), "vulnerabilities" : del(select(.[0][0] == .[0][0])[][0]) | map({ "affected": .[0], "installed": .[1], "description": .[2], "id": .[3] }) })'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment