1

I've recently started coded in python and just started using TinyDB. I got the insert, remove and update working but i can't figure out how to retrieve a value from my data.

{"_default": {"1": {"name": "Sarah", "value": 8}, "2": {"name": "John", "value": 9}}}

How do i get the value from a specific name for example?

JohnDoe
  • 23
  • 1
  • 4
  • [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) Add your code , what have you tried. – Morse Mar 27 '18 at 00:48
  • possible duplicate of [read from json](https://stackoverflow.com/questions/7771011/parse-json-in-python?noredirect=1&lq=1) – Morse Mar 27 '18 at 01:03
  • Possible duplicate of [Parse JSON in Python](https://stackoverflow.com/questions/7771011/parse-json-in-python) – Morse Mar 27 '18 at 01:04

1 Answers1

2

Try

from tinydb import TinyDB, Query
db = TinyDB('<your json path>')

# Get data from `Sarah`
result = db.get(Query()['name'] == 'Sarah')

Then your value should be result.get('value')

enpith
  • 1,540
  • 2
  • 10
  • 11