jq icon indicating copy to clipboard operation
jq copied to clipboard

Invalid numeric literal error when the input preceded by non-json line

Open arbitrary-dev opened this issue 3 years ago • 3 comments

Describe the bug There's an invalid numeric literal error when the input preceded by non-json line.

To Reproduce

$ cat broken.json; echo -n "\nJQ output:\n\n"; jq -Rr 'fromjson // .' broken.json
dummy
{"wat-da":100}
{"work-dat":"100"}

JQ output:

jq: error (at broken.json:1): Invalid numeric literal at EOF at line 1, column 5 (while parsing 'dummy')
jq: error (at broken.json:2): Invalid numeric literal at line 1, column 14 (while parsing '{"wat-da":100}')
{
  "work-dat": "100"
}

$ cat moved.json; echo -n "\nJQ output:\n\n"; jq -Rr 'fromjson // .' moved.json  
{"wat-da":100}
{"work-dat":"100"}
dummy

JQ output:

{
  "wat-da": 100
}
{
  "work-dat": "100"
}
jq: error (at moved.json:3): Invalid numeric literal at EOF at line 1, column 5 (while parsing 'dummy')

Expected behavior

$ cat broken.json; echo -n "\nJQ output:\n\n"; jq -Rr 'fromjson // .' broken.json
dummy
{"wat-da":100}
{"work-dat":"100"}

JQ output:

jq: error (at broken.json:1): Invalid numeric literal at EOF at line 1, column 5 (while parsing 'dummy')
{
  "wat-da": 100
}
{
  "work-dat": "100"
}

Environment (please complete the following information):

  • OS and Version: Gentoo Linux
  • jq version:
$ jq --version
jq--

$ equery l jq
* Searching for jq ...
[IP-] [  ] app-misc/jq-1.7_pre20201109:0

arbitrary-dev avatar Jan 28 '22 12:01 arbitrary-dev

Seems similar to https://github.com/stedolan/jq/pull/2400?

wader avatar Jan 28 '22 12:01 wader

Could be.

arbitrary-dev avatar Jan 28 '22 13:01 arbitrary-dev

It is definitely connected. I just tested it and #2400 fixes this issue too.

thalman avatar Mar 31 '22 14:03 thalman

This bug was fixed by #2400 (c4d39c4d22f2b12225ca1b311708f7e084ad9ff8).

itchyny avatar Jun 28 '23 23:06 itchyny