0

How do I search an object imbedded in a list? The user needs to be able to search for a title's text.

Here's the JSON:

"titles": [
    {
      "languageCode": "da", 
      "text": "Odysseus"
    }
  ],

Here's the code:

from tinydb import TinyDB, Query
db = TinyDB('db.json')
Event = Query()
db.search(Event.titles.text == 'Odysseus')

But the above example is obviously not right.

1 Answers1

2

Create a second Query object and use that to search your list object:

from tinydb import TinyDB, Query
db = TinyDB('db.json')
Event = Query()
Title = Query()
db.search(Event.titles.any(Title.text == 'Odysseus'))

This is not immediately obvious from the TinyDB docs.