'Remove unused keys from JSON file

Hello I'm looking for the best way to automatize my problem: I am working on a web application in which I use JSON translation files that have this form:

{ "unique_key" : "value"}

I have several files, one for each supported language, which all have the same number of items.

Ex :

i18n_en.json

{ "greeting" : "Hello"}

i18n_fr.json

{ "greeting" : "Bonjour"}

I have very badly managed the evolution of these files, and I end up with keys that are no longer used (I easily think 30% of the ~500 keys), the problem being that I don't know which ones. And that I would have to manually search through the entire architecture of my application to find those that are used and redo a clean file.

My idea to automate this process being:

  1. Open one of the JSON files (no matter which one, they all have the same number of keys).
  2. Loop for each key
  3. For each key, browse the entire architecture of my project ( by looking only in the *.html or *.js files)
  4. If we find an occurrence of this key, create an entry in a new clean json with the key + value of it.

I don't really know which language to use that would be optimized for this kind of task, thank you for guiding me!



Solution 1:[1]

Maybe something like i18next-scanner will be useful. You are not the first with such a problem.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1