jq: convert array to object indexed by filename?
问题 Using jq how can I convert an array into object indexed by filename, or read multiple files into one object indexed by their filename? e.g. jq -s 'map(select(.roles[]? | contains ("mysql")))' -C dir/file1.json dir/file2.json This gives me the data I want, but I need to know which file they came from. So instead of [ { "roles": ["mysql"] }, { "roles": ["mysql", "php"] } ] for output, I want: { "file1": { "roles": ["mysql"] }, "file2": { "roles": ["mysql", "php"] } } I do want the ".json" file