You are not logged in.

#1 2022-12-16 11:00:29

SupKurtJ
Member
Registered: 2015-07-18
Posts: 46

[SOLVED] Error with jq

Hi,

I try to get three value from json output :

curl -sH 'Snap-Device-Series: 16' http://api.snapcraft.io/v2/snaps/info/spotify | jq -r '.[] | .[] | select(.channel.name == "edge") | .download."sha3-384", .download.url, .version'            

a6ed06cd37b20b54ef7fb31b91f01a26c89231388529f6b3eab717a8fc299252949760af8668e47179ef592a9a14a2f7
https://api.snapcraft.io/api/v1/snaps/download/pOBIoZ2LrCB3rDohMxoYGnbN14EHOgD7_62.snap
1.1.99.878.g1e4ccc6e

jq: error (at <stdin>:1): Cannot iterate over null (null)

As you can see, I have this error jq: error (at <stdin>:1): Cannot iterate over null (null).

The only way I found to avoid it, it is to add 2>/dev/null like this :

curl -sH 'Snap-Device-Series: 16' http://api.snapcraft.io/v2/snaps/info/spotify | jq -r '.[] | .[] | select(.channel.name == "edge") | .download."sha3-384", .download.url, .version' 2>/dev/null 
a6ed06cd37b20b54ef7fb31b91f01a26c89231388529f6b3eab717a8fc299252949760af8668e47179ef592a9a14a2f7
https://api.snapcraft.io/api/v1/snaps/download/pOBIoZ2LrCB3rDohMxoYGnbN14EHOgD7_62.snap
1.1.99.878.g1e4ccc6e

But may be, do you have a better solution, more clean ?

Thank you so much smile

Last edited by SupKurtJ (2022-12-16 14:02:39)

Offline

#2 2022-12-16 12:47:47

saf1
Member
Registered: 2011-04-04
Posts: 17

Re: [SOLVED] Error with jq

try this:

curl -sH 'Snap-Device-Series: 16' http://api.snapcraft.io/v2/snaps/info/spotify \
    | jq -r '."channel-map"[] | select(.channel.name == "edge") | .download."sha3-384", .download.url, .version'
a6ed06cd37b20b54ef7fb31b91f01a26c89231388529f6b3eab717a8fc299252949760af8668e47179ef592a9a14a2f7
https://api.snapcraft.io/api/v1/snaps/download/pOBIoZ2LrCB3rDohMxoYGnbN14EHOgD7_62.snap
1.1.99.878.g1e4ccc6e

Offline

#3 2022-12-16 14:02:18

SupKurtJ
Member
Registered: 2015-07-18
Posts: 46

Re: [SOLVED] Error with jq

Oh thanks !!!
It work smile

Offline

#4 2023-07-21 15:28:05

eujian
Member
Registered: 2023-07-20
Posts: 4
Website

Re: [SOLVED] Error with jq

saf1 wrote:

try this:

curl -sH 'Snap-Device-Series: 16' http://api.snapcraft.io/v2/snaps/info/spotify \
    | jq -r '."channel-map"[] | select(.channel.name == "edge") | .download."sha3-384", .download.url, .version'
a6ed06cd37b20b54ef7fb31b91f01a26c89231388529f6b3eab717a8fc299252949760af8668e47179ef592a9a14a2f7
https://api.snapcraft.io/api/v1/snaps/download/pOBIoZ2LrCB3rDohMxoYGnbN14EHOgD7_62.snap
1.1.99.878.g1e4ccc6e

Thank You


Layanan Aplikasi Sisko Terbaik | Aplikasi Ujian Online

Offline

#5 2023-11-21 09:50:12

oceanhoster
Member
Registered: 2023-11-21
Posts: 2
Website

Re: [SOLVED] Error with jq

saf1 wrote:

try this:

curl -sH 'Snap-Device-Series: 16' http://api.snapcraft.io/v2/snaps/info/spotify \
    | jq -r '."channel-map"[] | select(.channel.name == "edge") | .download."sha3-384", .download.url, .version'
a6ed06cd37b20b54ef7fb31b91f01a26c89231388529f6b3eab717a8fc299252949760af8668e47179ef592a9a14a2f7
https://api.snapcraft.io/api/v1/snaps/download/pOBIoZ2LrCB3rDohMxoYGnbN14EHOgD7_62.snap
1.1.99.878.g1e4ccc6e

Nice..thank You


Layanan Hosting Indonesia Terbaik | Hosting Terbaik Indonesia

Offline

Board footer

Powered by FluxBB