Jq: "parse error: Invalid numeric literal at line 1, column 9" on what I think is valid JSON

Created on 21 Mar 2016  Â·  15Comments  Â·  Source: stedolan/jq

I'm getting this error:

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

but I think the JSON is valid.

Here is the sample json:

{"id": 746, "type": "job_template", "url": "/api/v1/job_templates/746/", "related": {"created_by": "/api/v1/users/2/", "inventory": "/api/v1/inventories/8/", "project": "/api/v1/projects/12696/", "credential": "/api/v1/credentials/23/", "last_job": "/api/v1/jobs/32219/", "next_schedule": "/api/v1/schedules/251/", "launch": "/api/v1/job_templates/746/launch/", "jobs": "/api/v1/job_templates/746/jobs/", "activity_stream": "/api/v1/job_templates/746/activity_stream/", "schedules": "/api/v1/job_templates/746/schedules/"}, "summary_fields": {"credential": {"name": "aws-qa", "description": "The key, for QA to run jmeter tests etc. Eventually we should get them their own key...", "kind": "ssh", "cloud": false}, "project": {"name": "master - elastichosts", "description": "Repo for all elastichosts configs", "status": "successful"}, "last_job": {"name": "Deploy", "description": "Description", "finished": "2016-03-21T20:33:18.339Z", "status": "successful", "failed": false}, "last_update": {"name": "Deploy", "description": "Deploy", "status": "successful", "failed": false}, "inventory": {"name": "QA", "description": "Our QA infrastructure", "has_active_failures": true, "total_hosts": 29, "hosts_with_active_failures": 6, "total_groups": 33, "groups_with_active_failures": 2, "has_inventory_sources": true, "total_inventory_sources": 7, "inventory_sources_with_failures": 1}, "created_by": {"id": 2, "username": "someone", "first_name": "Someone", "last_name": "Else"}, "can_copy": true, "can_edit": true, "recent_jobs": [{"status": "successful", "finished": "2016-03-21T20:33:18.339Z", "id": 32219}, {"status": "successful", "finished": "2016-03-21T20:21:25.589Z", "id": 32217}, {"status": "failed", "finished": "2016-03-21T20:06:28.094Z", "id": 32215}, {"status": "successful", "finished": "2016-03-21T17:25:23.170Z", "id": 32209}, {"status": "successful", "finished": "2016-03-15T16:50:01.540Z", "id": 31761}, {"status": "successful", "finished": "2016-03-15T16:43:14.388Z", "id": 31758}, {"status": "successful", "finished": "2016-03-15T16:23:10.750Z", "id": 31753}, {"status": "successful", "finished": "2016-03-10T19:43:24.518Z", "id": 31539}, {"status": "successful", "finished": "2016-03-10T19:13:40.928Z", "id": 31535}, {"status": "successful", "finished": "2016-03-10T18:54:35.355Z", "id": 31530}]}, "created": "2014-11-21T03:21:30.504Z", "modified": "2016-03-21T20:21:52.576Z", "name": "Description", "description": "Description", "job_type": "run", "inventory": 8, "project": 12696, "playbook": "deploy.yml", "credential": 23, "cloud_credential": null, "forks": 2, "limit": "107.6.4.172,107.6.4.104", "verbosity": 1, "extra_vars": "application_version: qa\ncdn: true\njs_versioned: true\nbuild_number: 19846", "job_tags": "", "force_handlers": false, "skip_tags": "", "start_at_task": "", "last_job_run": "2016-03-21T20:33:18.339Z", "last_job_failed": false, "has_schedules": false, "next_job_run": "2016-02-17T22:18:00Z", "status": "successful", "host_config_key": "", "ask_variables_on_launch": true, "survey_enabled": false, "become_enabled": false}

Most helpful comment

For future visitors, this was what was happening to me too - curl was returning the headers in the response. To remove them, take out the -i flag in your curl command.

All 15 comments

I've given your input as posted to various versions of jq going back to jq 1.3, and they all agree the input is valid. If you cannot easily resolve the issue yourself, please provide further details, notably the output of 'jq --version' and of uname -a or equivalent.

jq --version
jq-1.5

uname -a
Linux ip-10-0-0-143 4.1.17-22.30.amzn1.x86_64 #1 SMP Fri Feb 5 23:44:22 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

Oops, then I put that JSON in a file and it works:

cat jq-test | jq .status
"successful"

I guess I have to process the result of the curl command to use it in the same way? It looks identical when I print it out to the screen (to me).

If the curl command produces nothing but JSON on stdout, then you should be able to pipe curl directly into jq.

Yes, I see the problem. The header is getting output too, I thought that was from a previous part of the script. This is not a bug, I will close it. Thank you for your help!

PLS use cat /tmp/data.log | jq .
Do not use grep "KEY" /tmp/data.log | jq .

For future visitors, this was what was happening to me too - curl was returning the headers in the response. To remove them, take out the -i flag in your curl command.

jq does not work for numbers.

@ajaysharmamca jq _does_ work for numbers. Perhaps you could share some
details around the particular issue you're having?

On Wed, Jan 9, 2019 at 3:57 AM Ajay Sharma notifications@github.com wrote:

jq does not work for numbers.

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/stedolan/jq/issues/1119#issuecomment-452620118, or mute
the thread
https://github.com/notifications/unsubscribe-auth/ADQ4V0DaiTYgxbGsp83cEWMyV6ic1HtOks5vBa8QgaJpZM4H1jk1
.

my application spits a JSON that is incompatible with jq
"{ 'code': '200', 'status': 'success'}"
the internal quotes are single. jq should a flag to invert the quotes.
Is there a workaround?

my application spits a JSON that is incompatible with jq
"{ 'code': '200', 'status': 'success'}"
the internal quotes are single.

@falves1 Your application does not produce valid JSON. The JSON specification requires double-quoted strings. jq does not (and will not) support single-quoted strings.

I'd recommend seeing if your application can produce valid JSON instead.

@falves1 - The jq FAQ has a whole section on dealing with quasi-JSON: https://github.com/stedolan/jq/wiki/FAQ#processing-not-quite-valid-json

Another tip I found is to use json.dumps to get dobulequotes. Instead of

print(your_json_dict)

do

import json
print(json.dumps(your_json_dict))

this will print valid json to stdout.

And piping output into jq from something like the Azure az CLI, which is colourised by the terminal, you may also get issues with the shell colour codes. This nice printf statement may shine a light.

git push heroku master
Enumerating objects: 112, done.
Counting objects: 100% (112/112), done.
Delta compression using up to 4 threads
Compressing objects: 100% (101/101), done.
Writing objects: 100% (112/112), 1.40 MiB | 46.00 KiB/s, done.
Total 112 (delta 37), reused 73 (delta 5)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Node.js app detected
remote: parse error: Unmatched '}' at line 57, column 1
remote: ! Unable to parse package.json
remote:
remote:
remote: -----> Build failed
remote:
remote: We're sorry this build is failing! You can troubleshoot common issues here:
remote: https://devcenter.heroku.com/articles/troubleshooting-node-deploys
remote:
remote: If you're stuck, please submit a ticket so we can help:
remote: https://help.heroku.com/
remote:
remote: Love,
remote: Heroku
remote:
remote: ! Push rejected, failed to compile Node.js app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to desolate-bayou-17052.
remote:
To https://git.heroku.com/desolate-bayou-17052.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/desolate-bayou-17052.git'
//Hi! anyone can you help me out , i am getting error when I push on heroku using command (git push heroku master) , help seeker.

remote: parse error: Unmatched '}' at line 57, column 1
remote: ! Unable to parse package.json

ask on stackoverflow

Was this page helpful?
0 / 5 - 0 ratings

Related issues

benjamin-bin-shen picture benjamin-bin-shen  Â·  3Comments

lhunath picture lhunath  Â·  3Comments

kelchy picture kelchy  Â·  4Comments

tischwa picture tischwa  Â·  4Comments

neowulf picture neowulf  Â·  3Comments