Skip to content

Enhancement: Include the file name in parse error messaging #1553

@GreenGremlin

Description

@GreenGremlin

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions