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

Extract oldest entry from JSON

$
0
0

I'm trying to get a curl response and be able to call it like an object. I've been googling for a while and have seen a lot of answers around jq. I've been trying to make that work but I can't seem to find the exact syntax. My ideal solution is that I grab all the uploaded_at values, then sort, then determine which is the oldest.

This is my curl command:

url="https://api-cloud.browserstack.com/app-automate/recent_apps"curl -u "xxx:xxx" -X GET "$url"

It returns something like:

[{"app_name":"FlyreelSample.ipa","app_version":"1.1.0","app_url":"bs://76867867","app_id":"76867867","uploaded_at":"2024-08-21 14:41:53 UTC"}, {"app_name":"FlyreelSample.ipa","app_version":"1.1.0","app_url":"bs://8567463","app_id":"8567463","uploaded_at":"2024-08-21 14:40:29 UTC"}, {"app_name":"app-stage-debug.apk","app_version":"1.0","app_url":"bs://834534534","app_id":"834534534","uploaded_at":"2024-08-12 15:00:34 UTC"}]

I've tried the following command:

curl -u "xxxx:xxxxx" -X GET "$url" | jq -r '.uploaded_at'

And I get the following error:jq: error (at <stdin>:0): Cannot index array with string "uploaded_at"

I also tried some sed and Awk solutions. Also tried putting it to a file but also didn't work. It never put the values into the file

curl -u "xxxx:xxxxx" -X GET "$url" -d @test.txt

Viewing all articles
Browse latest Browse all 612

Trending Articles



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