Skip to content

Instantly share code, notes, and snippets.

@igorsol
igorsol / bear-jq.md
Last active June 12, 2021 13:40
json filtering with jq utility

So I suddenly discovered that compile_commands.json files generated by the Bear tool contain duplicate entries despite the fact Bear's documentation says it should filter out duplicates. Probably that was result of the outdated (2 years old) version of the Bear - now I updated it but I had no time to check if this issue is already fixed.

How to filter out duplicate entries from a JSON array with thousands of elements? And preferably leave only the last element of the group because it contains the most up-to-date compilation parameters?

One way is just remove compile_commands.json and rebuild whole project - but that could be very tedious because on my machine it takes more than an hour to rebuild the project which I work on. And I have a dosen of different versions in separate directories... After some thinknig I recalled a tool called jq which is 'JSON query'. I had some doubts if I will be able to do my specific task with this tool so I went to documentation page:

Keybase proof

I hereby claim:

  • I am igorsol on github.
  • I am igorsol (https://keybase.io/igorsol) on keybase.
  • I have a public key ASBwtuEwL9mx8n3QEoVvyp6qk24__D4DdPlfaQR8X4pE-Ao

To claim this, I am signing this object: