1

I have JSON file having following structure

{  
     "type":[  
        "apple-shimle",
        "king"
     ],

     "json-object":{  
        "test":"hi"
     }
  }

How to search for test == "hi" using TinyDB python only. Iam able to fetch "json-object" using search() but not "test".

Nawap
  • 43
  • 5
  • Can you show us what you got so far? The code, I mean. – francisco sollima Feb 14 '18 at 16:11
  • @franciscosollima here is the code i tried to find "json-object" db.search(Check['json-object'].exists()) it returned {'type': ['apple-shimle', 'king'], 'json-object': {'test': 'hi'}} Now iam actually interested in existence of "test" so, db.search(Check['test'].exists()) this returned [ ], means not exist I tried this because i know mongodb checks inside nested json object. – Nawap Feb 14 '18 at 16:49
  • 2
    Try `db.search(Check['json-object']['test'].exists())` – francisco sollima Feb 16 '18 at 13:02

1 Answers1

0

As from the docs you can query nested fields like this:

db.search(Check['json-object']['test'].exists())
timo.rieber
  • 3,727
  • 3
  • 32
  • 47