Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Write JSON-array to stdout with one line pr element

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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":""}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading