Quantcast
Channel: Active questions tagged jq - Stack Overflow
Viewing all articles
Browse latest Browse all 657

jq command with several tables in the json path

$
0
0

My (huge) input file has many entries , what I want to extract is structured like that:

{"vulnerabilities": [      {"parentAlert": {"affectedVersions": [               {"answers": [                     {"willBeFixed": true,"fixedInPackage": "2.31.0"                     }                  ],"productName": "LDEwS"               },               {"answers": [                     {"willBeFixed": true,"fixedInPackage": "2.32.0"                     },                     {"willBeFixed": false,"fixedInPackage": "3.0.0"                     }                  ],"productName": "Foo"               }            ]         }      }  ]}

I want to extract the info of that type:

{"willBeFixed": true,"fixedInPackage": "2.31.0","productName": "LDEwS"}{"willBeFixed": true,"fixedInPackage": "2.32.0","productName": "Foo"}{"willBeFixed": false,"fixedInPackage": "3.0.0","productName": "Foo"}

I can't find the proper jp command. Can you please help to find out ?

The following command seems to work fine (for one field):

.vulnerabilities[] |{   willBeFixed: .parentAlert.affectedVersions[].answers[].willBeFixed}
{"willBeFixed": true}{"willBeFixed": true}{"willBeFixed": false}

But not the following ones.

.vulnerabilities[] |{   willBeFixed:    .parentAlert.affectedVersions[].answers[].willBeFixed,   fixedInPackage: .parentAlert.affectedVersions[].answers[].fixedInPackage}
.vulnerabilities[] |{   willBeFixed:    .parentAlert.affectedVersions[].answers[].willBeFixed,   fixedInPackage: .parentAlert.affectedVersions[].answers[].fixedInPackage,   productName:    .parentAlert.affectedVersions[].productName}

It gives all possible combinations between the 2 fields in the first one and between the 3 fields in the second one.

{"willBeFixed": true,"fixedInPackage": "2.31.0"}{"willBeFixed": true,"fixedInPackage": "2.32.0"}{"willBeFixed": true,"fixedInPackage": "3.0.0"}{"willBeFixed": true,"fixedInPackage": "2.31.0"}...

Viewing all articles
Browse latest Browse all 657

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>