Azzarian
Azzarian

Reputation: 175

Jq parse error: Invalid numeric literal at line 1, column 9

I am trying to get values from a json file from a url using curl and then printing specific keys with jq command (e.g. company). Unfortunately when I use: jq '.[] | .company' JB.json I get the error: parse error: Invalid numeric literal at line 1, column 9. I have checked the downloaded file with less and it looks exactly like in the url.

Some people suggested to use the -R option but it prints: jq: error: Cannot iterate over string

The url of the file is: https://jobs.github.com/positions.json?description=python&location=new+york

Upvotes: 1

Views: 5117

Answers (1)

peak
peak

Reputation: 116700

If you use curl -sS to retrieve the file, the '//'-style comments are skipped:

curl -Ss 'https://jobs.github.com/positions.json?description=python&location=new+york' | jq '.[] | .company' 
"BentoBox"
"Aon Cyber Solutions"
"Sesame"
"New York University"

So presumably your JB.json contains the "//"-style comments. The simplest workaround would probably be to filter out those first two lines (e.g. using sed (or jq!)) first.

Here's a jq-only solution:

< JB.json jq -Rr 'select( test("^//")|not)' |
   jq '.[] | .company' 

Upvotes: 2

Related Questions