-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"Invalid Numeric Literal" on colon following a single-quoted string (incorrect parser error message) #501
Comments
@bartgrantham - Later versions produce the same (confusing) error message, e.g.
The simplest demonstration of the issue may be:
|
This is a very long-standing issue with the JSON parser (not the parser for jq code, but the parser for JSON input). Essentially, the logic is: is it an array? nope. is it an object? nope. (...) well, it must be a number. parse error on a number. I suppose the fix is probably to choose a different error message if the invalid character is not in [0-9+-]. |
according to json.org a string is to be "wrapped in double quotes" so, use double and escape from $ echo "{\"foo\":\"bar\"}" | jq .foo
"bar" |
We've found the best practice to be single quotes around json data and also $ echo '{"foo":"bar"}' | jq '.foo' It allows you to use double quotes without escaping and prevents the shell Also, 1.4 should exist as precompiled binaries on the website and is also On Sun, Nov 23, 2014, 11:44 Jacob Berger notifications@github.com wrote:
|
@bergerjac, @wtlangford - I know single-quotes for strings are wrong, I mentioned at the beginning that I "absent-mindedly and incorrectly" used them. The issue is that the error produced is cryptic. |
Good point. I might look into a better error for the parser, but the issue On Sun, Nov 23, 2014, 12:29 Bart Grantham notifications@github.com wrote:
|
Of course, the Windows We really need something like a REPL to make Windows jq users happy... |
Ok, I have a big json dump (sql export) that gives this error. Any work-arounds to make it work with jq until this error is fixed? |
@delip - Since you have a big JSON dump, you are presumably reading it in as a file. In that case, from what you write, it would seem that the error message you see will give the line and column numbers of the invalid JSON. Thus it is unclear to me what kind of work-around you would like. That is, if your big json dump is invalid JSON, the simplest thing to do might be to fix it. |
@delip You have to give us an example. If the request is to have more sensible error messages from the JSON parser, that's another story. |
@nicowilliams, I know! I said it in the opening post that it was "incorrect", the bug is about the error messages being misleading. I even wrote it again in this thread, barely a page up from your comment:
|
Heheh, sorry @bartgrantham. |
PLS use cat /tmp/data.log | jq . |
Your pasted output from the preliminary command works for me when I pipe it
into your jq command. I suspect `/tmp/read` may be doing something
different when it's piped into jq? Try `echo "42fdfc072112624f" |
/tmp/read | tee test.out` and see what's in test.out?
…On Mon, Jun 11, 2018 at 9:55 AM mh-cbon ***@***.***> wrote:
hey guys, i m facing the same issue, but i don t understand.
Please take a look
$ echo "42fdfc072112624f" | /tmp/read | jq -r '.["42fdfc072112624f"]'
parse error: Invalid numeric literal at line 1, column 9
where preliminary command output is
$ echo "42fdfc072112624f" | /tmp/read
{
"42fdfc072112624f": "65465Uv38ByGCZU1WP18P"
}
????????
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#501 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ADQ4VyStuKNUas8FzoXl8W28hHv_YT0_ks5t7nbSgaJpZM4CQUNi>
.
|
Great! |
How i can update value of existing key using jw in shell script |
This error came up for me using |
@simesy That's because you're sending the content of If you really want to redirect the output of your shell script into jq with input redirection, you can do it in bash with |
whoo use curl then parse to jq like 'curl http://req.url/get | jq .' then get error like on top. just add -s on curl, like ' curl -s http://req.url/get | jq .' and everything be alright |
Curious why this was closed? v1.6 still outputs the same nonsense error if the input is not valid JSON.
|
@chet-manley yeah, I think maybe @wtlangford closed this by accident thinking it was a different bug report? This should be re-opened IMO.
|
Should definitely be re-opened. |
@stedolan @wtlangford Any guidance as to why this was closed without addressing the issue? |
@chet-manley if the file is using single quote, then it's not actually json format. A json payload must use quotation marks. This is based on the actual standard as per RFC 8259 (https://datatracker.ietf.org/doc/rfc8259) I think it's still a good feature to have it support single quotes. PS: The mistake that our engineer was doing is not specifying the file/format type in his request. So he was getting single quotes. As soon as he started specifying this, he got back quotations in his payloads. |
@nkhoury-payments This issue is not about single quotes vs. double quotes. This issue is about the misleading error message "Invalid numeric literal" when the error is the use of a single quote. That's what @chet-manley was referring to, and what this issue is about. Incedentally, it would be a huge mistake for jq to start supporting non-standard single quotes in JSON. |
@bartgrantham thanks for the clarification about the error message. |
I install jq from brew on macOS.
on iTerm.
I don't think you mayby understand what i say. |
jq processes the standard input |
@itchyny Wow.. Thanks! It was my mistake |
having this issue with 1.6 |
Confirm to have the issue with 1.6. Putting the output of a curl in a file and then cat test.json | jq . and everything works fine...chaining jq directly to the curl does not work :( |
Issue #501 has AGAIN been closed incorrectly, after apparently being incorrectly cross-linked with unrelated issues. This issue is about the misleading error message "Invalid numeric literal" when the error is the use of a single quote.
|
Can someone please reopen. This issue has not been adressed. A few more years and we can celebrate a decade. |
I am also getting this in jq 1.6 |
I have a payload (a certificate actually that is now destroyed) that is this:
And if I try to read it, with this command it will error:
Is this a bug or am I doing it wrong? |
@queglay - This is unrelated to this issue. As for your problem, I put the JSON in a file and was able to extract and base64-decode it properly with: I would suggest being very careful with a shell construction like this. You're piping an opaque blob of base64-encoded data through |
Interestingly, I can perform the operation without issue in a shell, but if run during a user data script on boot in ubuntu 18 on ec2, then the error crops up, so I can't reproduce it adhoc. Thanks for sharing your concern re the potential security bug. I have high confidence over the origin of both values, but honestly hadn't considered what you mention here. For my education sake if someone wanted to do harm by manipulation of $target_path what would an example be? |
Maybe do
|
@queglay - I have verified that with your JSON, For future reference, please ask usage questions related to jq at stackoverflow.com using the jq tag: |
I solved my issue by using printf instead of echo |
You can do something like |
EDIT (20150416): I KNOW IT'S INVALID JSON. THE BUG IS ABOUT THE NONSENSICAL ERROR MESSAGE
I get this from absent-mindedly and incorrectly using single-quotes:
This is under 1.3. Trying to reproduce under 1.4, but after 5 minutes of trying to build from source I'm just going to submit this and move on.
The text was updated successfully, but these errors were encountered: