Hello, as I’m in the process of cleaning up properties in a vault that has become a mess, I’d like t know if it’s possible to make a dataview query to have a table (or a list) of all property keys and values from my vault so that I can merge similar keys or values and delete unnecessary ones. (I remembered I had found a query that did the trick but I can’t find it anymore in the forum)
Things I have tried
Nothing as I’m not enough skilled with data view queries to do it
Ideally it could be a table with a column for the keys, one for the values used in each key and one displaying the number of times each value appears.
If you open the command menu (Cant remember the default shortcut, ctl-p for me) and look for “properties” you’ll find a command that shows all properties and counts (sorry) in the sidebar, from there is is easy to search specific ones. But I’ll watch the thread for a suggestion on how to see them all with values, good question.
You do have the option to loop through app.metadataCache.fileCache, and then look up the hash in app.metadataCache.metadataCache. Now you’ve got an object which holds both the frontmatter for keys and values, and frontmatterLinks which holds the links from the frontmatter.
Based on this information you should be able to get all the information you are requesting.
However, be forewarned that rendering a table based on this data can take some time as there is very much data to process in a decent sized vault.
Thanks @JohannSnyman I knew about the show vault properties command but I think having a more “panoramic” view could be very helpful mostly for the values of the keys as they could contain very similar values…
Thanks @holroy but I’m afraid this goes beyond my poor skills with dataview and dataviewjs…(and double thanks as it’s not the first time you show up helping…
I tried with chat gpt and it returns me the code below, is your method better? I noticed that the code generated by chat gpt is fast when querying but it slow down page scrolling…
Here’s the code I got:
const allValues = {};
for (let page of dv.pages().values) {
for (let [key, value] of Object.entries(page)) {
if (key !== 'file' && key !== 'tasks' && key !== 'list' && key !== 'backlinks') {
if (!allValues[key]) {
allValues[key] = [];
}
if (!allValues[key].includes(value)) {
allValues[key].push(value);
}
}
}
}
for (let [key, values] of Object.entries(allValues)) {
dv.header(3, key);
dv.list(values);
}
Your method will also include inline fields, which might or might not be what you want.
And I’m not sure what other side effects it has doing it this way, as you get all the metadata added by dataviewin addition to all the fields. And you’ll get both the original field keys, and the santised version of the field keys. Like Original field!Name and original-field-name (or something like that).
So not sure which variant would best suit your use case, and sadly I’m just on mobile for a few days now so can’t really post any solution I can build/test.