Skip to content

Instantly share code, notes, and snippets.

@falgon
Created Jun 1, 2022
Embed
What would you like to do?

これが

{
  [
    "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