scenarios when using 'jq' to parse JSON in a Bash script on Ubuntu 20.04
After trying multiple solutions online, I still can't figure this out. I've been struggling with this for a few days now and could really use some help. I'm trying to parse a JSON response from an API using `jq` in a Bash script on my Ubuntu 20.04 machine. The API response is a bit nested, and I'm specifically trying to extract the value of the `id` from an object inside an array. The command I'm using looks like this: ```bash response=$(curl -s 'https://api.example.com/data') id=$(echo $response | jq '.items[0].id') echo $id ``` However, when I run the script, I get the following behavior: ``` parse behavior: Invalid numeric literal at line 1, column 6 ``` I've confirmed that the API is responding with valid JSON by testing the `curl` command directly in the terminal. The response looks something like this: ```json { "items": [ { "id": 123, "name": "Item 1" }, { "id": 456, "name": "Item 2" } ] } ``` I suspect the scenario might be related to how I'm handling the `response` variable, especially since I didn't include any quotes around it in the `jq` command. After trying to debug, I wrapped `$response` in quotes like this: ```bash id=$(echo "$response" | jq '.items[0].id') ``` But that still leads to the same behavior. I've also tried using `-e` with `jq` to check for errors more verbosely: ```bash id=$(echo $response | jq -e '.items[0].id') ``` This outputs `null` instead of an behavior message, which makes me think the JSON parsing is failing silently. I’ve confirmed that `jq` is installed correctly by running `jq --version`, which returns `jq-1.6`. Am I missing something in the way I’m parsing the JSON, or is there an scenario with how the API response is being handled in the variable? Any help would be appreciated! What's the best practice here? Any suggestions would be helpful.