When I do jq 'whatever' *.json I can't easily identify which lines of the output were produced by each input file. I'd like to see an option (possibly on by default) to add something like "file1.json:" before each section.
Perhaps we could have $source variable that names the source of the
current input.
The workaround (in bash, for example) is to proceed like so:
for f in *.json
do
jq --arg file "$f" 'whatever' "$f"
done
where references to $file in 'whatever' will have the relevant file name.
In fact, I think this workaround is so good that if an "enhancement" is needed, it should wait until after jq 1.5 is released.
Fixed in #753.
@pkoppstein the problem with the workaround you illustrated is what happens when I am trying to actually run a filter across a group of json files. So for example aggregating objects into an array and I want to know where each object came from.
A way to handle this could be to create an interim json object with the filename added.
alljson=""
for f in *.json
do
alljson+=$(jq --arg file "$f" '{"data":.,"file":$file}' "$f")
done
I'm really not sure how to use $__loc__ to get the file and line number.
@vito-c - I think input_filename is more relevant here. It's in jq 1.5 and is easy to use. (See e.g. https://stedolan.github.io/jq/manual).
@pkoppstein I didn't see that one! so good :+1:
Most helpful comment
@vito-c - I think
input_filenameis more relevant here. It's in jq 1.5 and is easy to use. (See e.g. https://stedolan.github.io/jq/manual).