Dataview query from Kindle sync notes: nested fields in metadata

Things I have tried

I tried this query:

table author, asin, highlightsCount
from "050 📚 Sources/📖 Kindle"
sort author asc

The Metadata in the Kindle docs looks like this:

bookId: ‘55568’
title: ‘Letting Go: The Pathway of Surrender (English Edition)’
author: David R. Hawkins
asin: B00EY818TQ
lastAnnotatedDate: ‘2020-01-22’
bookImageUrl: ‘
highlightsCount: 27

but neither author, asin nor highlightsCount are displayed in the table.

I assume this is because the fields in the metadata are nested:
bookId: ‘55568’

What I’m trying to do

What would be the correct syntax for the query to produce a table with the above fields?

1 Like

Your assumption makes sense! Would you mind re-posting that metadata wrapped in a ``` code block the way you did for the dataview query? I can’t tell how it is doing the nesting of the data (a list??) thanks to the re-formatting that the forum did. :slight_smile: YAML seems to be kind of finicky about nesting and I’m finding that neither Obsidian nor dataview pick up any fields from my YAML if one of them is formatted wrong.

Let’s try again:

dash dash dash (sorry, I don’t know how to preserve the 3 dashes)
bookId: ‘41841’
title: >-
A Heart Blown Open: The Life & Practice of Zen Master Jun Po Denis Kelly
Roshi (English Edition)
author: Keith Martin-Smith
asin: B007R48LFS
lastAnnotatedDate: ‘2019-01-06’
bookImageUrl: ‘
highlightsCount: 1
dash dash dash

1 Like

Thank you, that is clearer but I admit that I am still confused! Things to try with dataview:

TABLE file.frontmatter FROM "oneFilenameToTestWith"

The expected output should be a list of all of those metadata fields, hence picking a single example file to use in the FROM. When I do something like what you copied in, I get a list with kindle-sync having a blank value and then the rest of the fields show up right below it, suggesting that it isn’t actually nesting and your original query should work.

However, if the output of the table is blank or empty then there’s a formatting error in your YAML and so it can’t be parsed correctly. (I wonder if there is a plugin to check and warn me about these formatting errors; it would be very useful right now!) Open the test file you used for your query and try manually removing things that look suspicious in the YAML (you could put them in the main part of the note and move them back later). I don’t have a great intuition for “suspicious” but a place I’d start would be the >- symbols and the line break before the words of the title in your example above. I can’t tell whether YAML cares about things like line breaks, tabs, and spaces. After you make a change, go back to your dataview table and see if the frontmatter shows up. (I have to go into and out of editing the dataview query to make sure the result refreshes because I turned off the setting that has it refresh automatically.) You could also try putting quotes around values and see whether that changes anything in your dataview result.

Once you can get the frontmatter to display in the table, you should be able to tell whether the keys you want are in fact nested inside something else. Hope that helps, good luck!

Thank you for your effort to support me!

This is what th result of your suggestion looks like:

This is the metadata:

This tells me, that the metadata is readable.
The thing that irritates me is the first field (kindle-sync) being empty and the following havening leading spaces or tabs. That’s what I mean with ‘nested’

1 Like

Well hurrah that the metadata is readable! I was finding it so easy to blank out that field in my own experiments by doing some YAML formatting mistake that I didn’t know was a mistake.

Thanks for the picture of the metadata: I definitely would not have been able to figure that out from your original post in this thread where the forum re-formatted it. I agree that the spacing makes it look nested, but it isn’t being displayed in a nested way in the dataview! (To see what a nested list looks like, for example, you could add a line like this rather silly example to your frontmatter:

whoRecommended: ["the librarian", "my friend from class", "my neighbor"]

and then rerun the table for the frontmatter. This list just has strings in it, not entire fields, but it should show up as a list in the dataview display.)

Can you add columns to your table with the data you actually want?
Staying with your test file, does this table show your data?

highlightsCount AS "Highlights"
FROM "frontmatterTestFile"

(or whatever you called your test file). If not, what about:

author, AS "Author via fm 1",
file.frontmatter['author'] AS "Author via fm 2"
FROM "frontmatterTestFile"

I don’t know what I expect to happen if you have a blank on author and try this table. More blanks? An error in Dataview?

I agree that the blank kindle-sync field is annoying! I don’t know how whatever you’re using to sync things from kindle uses that field, though.

I solved the problem by using this syntax:

table AS Autor ,kindle-sync.lastAnnotatedDate AS Datum, kindle-sync.highlightsCount AS Highlights
FROM "050 📚 Sources/📖 Kindle"

It seems, the ‘nesting’ thing can be worked around by preceding the fieldnames with ‘kindle-sync.’

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.