1

I tried many things to pick up all the values in relatives from JSON but didn't find how to make it works.
Thanks for any help and/or any advice.

I need to do it with the export ID=1 at first, I can only edit the second line with curl and jq.

bash:

export ID=1
curl 'url.json' | jq -r '.ID.relatives'

JSON:

"biography": {
      "fullName": "Richard Milhouse Jones",
      ],
      "placeOfBirth": "Scarsdale, Arizona",
      "firstAppearance": "Hulk Vol 2 #2 (April, 2008) (as A-Bomb)",
      "publisher": "Marvel Comics",
    },
    "connections": {
      "groupAffiliation": "Hulk Family; Excelsior (sponsor), Avengers (honorary member)",
      "relatives": "Marlo Chandler-Jones (wife); Polly (aunt); Mrs. Chandler (mother-in-law); Keith Chandler, Ray Chandler, three unidentified others (brothers-in-law)"
0stone0
  • 34,288
  • 4
  • 39
  • 64
sdrz
  • 13
  • 2
  • 3
    Please [edit] your post to add the valid JSON, and your attempts of solving your issue. – 0stone0 Jun 29 '22 at 20:47
  • 2
    You might be looking for either the `--arg` or the `--argjson` option to import a shell value with or without JSON encoding, i.e. here as string or as integer, respectively: `jq --arg id "$ID" '.[$id].relatives'` or `jq --argjson id "$ID" '.[$id].relatives'`. – pmf Jun 29 '22 at 20:55
  • This might help: [Passing bash variable to jq](https://stackoverflow.com/q/40027395/3776858) – Cyrus Jun 29 '22 at 21:00
  • Cyrus I've seen already what you send but I tried to read it again and I've found how to get my value. Thanks for your help Cyrus, pmf and 0stone0. – sdrz Jun 29 '22 at 21:17
  • Please add an answer to the question if it solves the problem so that future readers with similar questions can find it. – knittl Aug 13 '22 at 19:33
  • The JSON quoted in the question is not valid JSON (missing opening and closing curly braces, stray closing square bracket) – knittl Sep 06 '22 at 19:00

0 Answers0