I'm trying to get more information on an error in jq.
I have two files, let's call them file1.json and file2.json, both of which contain an array of objects that I want to join by a common property, .id. I'm using a combination of the INDEX and JOIN built-in functions. (Shout-out to this incredibly helpful blog post for helping me understand how INDEX and JOIN work.)
I'm running the following command:
jq '[JOIN(INDEX(input[], .id); .[]; (.id|tostring); add)]' file1.json file2.json > joined.jsonwhich gives me the following error:
jq: error (at file2.json:11329): breakLine 11329 is the last line of file2.json, which contains the closing ] for the JSON array. Here is the end of file2.json
1 [ ... ..., 11304 { 11305 "count_by_file_type": { 11306 "gitignore": 1, 11307 "json": 1 11308 }, 11309 "id": 972 11310 }, 11311 { 11312 "count_by_file_type": { 11313 "html": 3 11314 }, 11315 "id": 975 11316 }, 11317 { 11318 "count_by_file_type": { 11319 "html": 3 11320 }, 11321 "id": 994 11322 }, 11323 { 11324 "count_by_file_type": { 11325 "html": 2 11326 }, 11327 "id": 999 11328 } 11329 ]I have no idea what's causing the break to happen (I'm assuming it's the JOIN function but really I don't know that for sure). I know there's a debug function but I don't believe it's possible to use it to "step into" a function. Because it's erroring on the last line of the file I thought maybe it found something unexpected instead of EOF, or that somehow it was invalid JSON. I checked with a validator and file2.json is valid JSON.
If I could drill down into the JOIN function and debug the intermediate inputs, maybe jq would give me a more helpful error message. I've tried try-catch but it's not producing the output I'd want (if I even knew what I wanted it to print on failure). I feel like I don't even have enough information to know what to try next.
Does anybody have ideas for how I could debug this further? Thanks!!