-1

I try to slice the json file but it's giving me the error:

jq: error (at result2.json:0): Cannot index array with string "url"

I am trying to parse the following json file

code ss

I want to access six reference links from this list. I tried using the following code but it's giving me an error.

jq -r .result.CVE_Items[].cve.references.reference_data[0:5].url result2.json

I am fairly new to json parsing so i am having a tough time overcoming these issues :(

2
  • Welcome to SO. Please follow the minimal reproducible example guidelines. In particular, in your case, a small sample of the input JSON should be provided as part of the question. Providing a link to an image of incomplete JSON is seldom useful and never a satisfactory substitute.
    – peak
    Commented Dec 2, 2020 at 14:00
  • Go it! I'll keep that in mind :) Commented Dec 3, 2020 at 10:26

1 Answer 1

0

.reference_data[0:5] produces a slice, i.e. an array, so in your query, you would need to itemize it, e.g. by appending []:

.reference_data[0:5][]
1
  • Thanks! I kind of feel dumb asking such questions but thanks for bearing with me! Commented Dec 2, 2020 at 14:41

Not the answer you're looking for? Browse other questions tagged or ask your own question.