I would like to get the id 7721291801 from here with the jq
command.
{
"total_count": 1,
"entries": [
{
"type": "group",
"id": "7721291801",
"name": "test-group 1",
"group_type": "managed_group"
}
],
"limit": 100,
"offset"—0
}
The following command results in an error:
commands executed:
curl-i-X GET "https://api.box.com/2.0/groups" - H "Authorization: Bear xxxxxxxxx" | jq-R'fromjson? '|jq'.[].id'
error messages:
jq:error(at<stdin>:13):Cannot index number with string "id"
Please tell me how to extract the ID value.
json jq
entries
If you want to take out the following, it should be jq'.entries[]|.id'
as stated in the comment.
If you want to extract all the id's from the child elements of an indefinite hierarchy, you can find them in jq'..|.id?|select(.!=null)'
.
Note: Access JSON's deep hierarchy without worrying about it
I passed the file from the standard input and checked it.
|jq..
or later.
cat<<EOF|jq-r'.entries[].id'
{
"total_count": 1,
"entries": [
{
"type": "group",
"id": "7721291801",
"name": "test-group 1",
"group_type": "managed_group"
}
],
"limit": 100,
"offset"—0
}
EOF
The -r
option should be added.
574 Who developed the "avformat-59.dll" that comes with FFmpeg?
618 Uncaught (inpromise) Error on Electron: An object could not be cloned
915 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
572 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
© 2024 OneMinuteCode. All rights reserved.