jq
jq copied to clipboard
Enhancement: Include the file name in parse error messaging
It would be helpful if the filename were included in parse error messages. While this could fairly easily be handled by a script, it would be nice if this functionality was included in jq.
Example script
#!/usr/bin/env bash
set -e
for file in data/*.json; do
some_data=$(jq . file)
done
Currently, a parse error produces the following output.
$ ./parse_data.sh
parse error: Expected another key-value pair at line 20, column 3
It would be helpful if it output something like this.
$ ./parse_data.sh
Error parsing file data/2017-10-data.json: Expected another key-value pair at line 20, column 3
Even better, this feature could be added behind a --verbose flag and include the context of the error.
$ ./parse_data.sh
Error parsing file data/2017-10-data.json:
19 | "name": "Bob Smith",
> 20 | },
^
21 | {
Expected another key-value pair at line 20, column 3
I believe this is already so in master. 1.6 is coming.
+1 for this enhancement 😄
Even on jq-1.6 (as reported by jq --version), parse errors still return the same filename-agnostic message.
Still an issue in 2023. There should be a switch that includes the full file path in the erorr message.
This is especially a pain in the rear when processing thousands of small json files with jq in parallel fashion.
7 years later... still not implemented 🤦♂️
🤦♂️
Did a draft PR #3146
I wonder what @nicowilliams referred to about as this being fixed in master? maybe reporting of current name:line of input on uncaught error? that is the only place currently where i see jq_util_input_get_position is used
I wonder what @nicowilliams referred to about as this being fixed in master?
Here's an example output of calling jq 1.6 over thousands of JSON files:
...
parse error: Invalid numeric literal at line 1, column 5
parse error: Invalid numeric literal at line 1, column 16
parse error: Invalid numeric literal at line 1, column 16
parse error: Invalid numeric literal at line 1, column 16
parse error: Invalid numeric literal at line 1, column 16
parse error: Invalid literal at line 1, column 5
parse error: Invalid numeric literal at line 1, column 16
parse error: Invalid numeric literal at line 1, column 2
parse error: Invalid numeric literal at line 1, column 2
parse error: Invalid numeric literal at line 1, column 5
parse error: Invalid numeric literal at line 1, column 5
parse error: Invalid numeric literal at line 1, column 5
jq: error (at ./573455af-5842-48b7-9add-7a7c0349b502.json:260): Cannot index array with string "foo"
parse error: Invalid numeric literal at line 1, column 5
parse error: Invalid numeric literal at line 1, column 2
parse error: Invalid literal at line 1, column 5
parse error: Invalid literal at line 1, column 5
parse error: Invalid literal at line 1, column 5
parse error: Invalid literal at line 1, column 5
parse error: Invalid numeric literal at line 1, column 15
parse error: Invalid numeric literal at line 1, column 2
parse error: Invalid numeric literal at line 1, column 5
parse error: Invalid numeric literal at line 1, column 2
parse error: Invalid numeric literal at line 1, column 2
parse error: Invalid numeric literal at line 1, column 4
parse error: Invalid numeric literal at line 2, column 0
parse error: Invalid numeric literal at line 1, column 3
parse error: Invalid numeric literal at line 1, column 2
parse error: Invalid numeric literal at line 1, column 15
parse error: Invalid numeric literal at line 2, column 0
parse error: Invalid numeric literal at line 1, column 2
parse error: Invalid literal at line 1, column 5
parse error: Invalid numeric literal at line 1, column 2
parse error: Invalid numeric literal at line 1, column 3
parse error: Invalid numeric literal at line 1, column 2
parse error: Invalid numeric literal at line 1, column 2
parse error: Invalid numeric literal at line 1, column 3
...
...so there is definitely some type of error which shows the filename!