Joseph Wahba Joseph Wahba - 1 year ago 121
Python Question

Python searching a Json with key value

I'm having a JSON file and I'm trying to do a search using the values ( not the keys). Is there a built in function in Python that does so?

[["2778074170846781111111110", "a33104eb1987bec2519fe051d1e7bd0b4c9e4875"],
["2778074170846781111111111", "f307fb3db3380bfd27901bc591eb025398b0db66"]]

I thought of this approach. Loading the file into a list and start searching. Is there a more efficient way?

def OptionLookUp(keyvalue):
with open('data.json', 'r') as table:
x= json.loads(table)

Answer Source

After your edit I can say that there is no faster/more efficient way than turning your JSON into python 2-dimensional list and loop through each node and compare second field with your "keyvalue".

EDIT: faster/more efficient

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download