-1

I have a JSON-array that I would like to write to the STDOUT with one element pr line such that our logging tool, Grafana, can more easily pick it up.

# Our data
[
  {
    "PkgName": "perl-base",
    "Severity": "MEDIUM",
    "VulnerabilityID": "CVE-2020-16156",
    "InstalledVersion": "5.34.0-3ubuntu1",
    "FixedVersion": "",
    "Title": "perl-CPAN: Bypass of verification of signatures in CHECKSUMS files",
    "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2020-16156",
    "namespace": "la",
    "image": ""
  },
  {
    "PkgName": "tar",
    "Severity": "LOW",
    "VulnerabilityID": "CVE-2019-9923",
    "InstalledVersion": "1.34+dfsg-1build3",
    "FixedVersion": "",
    "Title": "tar: null-pointer dereference in pax_decode_header in sparse.c",
    "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2019-9923",
    "namespace": "la",
    "image": ""
  }
]

What I need:

{"PkgName": "perl-base", "Severity": "MEDIUM", "VulnerabilityID": "CVE-2020-16156", "InstalledVersion": "5.34.0-3ubuntu1", "FixedVersion": "", "Title": "perl-CPAN: Bypass of verification of signatures in CHECKSUMS files", "PrimaryURL": "https://avd.aquasec.com/nvd/cve-2020-16156", "namespace": "la", "image": ""}
{"PkgName": "tar","Severity": "LOW","VulnerabilityID": "CVE-2019-9923","InstalledVersion": "1.34+dfsg-1build3","FixedVersion": "","Title": "tar: null-pointer dereference in pax_decode_header in sparse.c","PrimaryURL": "https://avd.aquasec.com/nvd/cve-2019-9923","namespace": "la","image": ""}

Is there an easy way to achieve this using jq or a similar default ubuntu tool?

Esben Eickhardt
  • 3,183
  • 2
  • 35
  • 56

1 Answers1

2

Running jq -c '.[]' produces:

$ jq -c '.[]' data.json
{"PkgName":"perl-base","Severity":"MEDIUM","VulnerabilityID":"CVE-2020-16156","InstalledVersion":"5.34.0-3ubuntu1","FixedVersion":"","Title":"perl-CPAN: Bypass of verification of signatures in CHECKSUMS files","PrimaryURL":"https://avd.aquasec.com/nvd/cve-2020-16156","namespace":"la","image":""}
{"PkgName":"tar","Severity":"LOW","VulnerabilityID":"CVE-2019-9923","InstalledVersion":"1.34+dfsg-1build3","FixedVersion":"","Title":"tar: null-pointer dereference in pax_decode_header in sparse.c","PrimaryURL":"https://avd.aquasec.com/nvd/cve-2019-9923","namespace":"la","image":""}
larsks
  • 277,717
  • 41
  • 399
  • 399