MCPcopy Index your code
hub / github.com/HelloZeroNet/ZeroNet / queryFile

Function queryFile

src/util/QueryJson.py:6–26  ·  view source on GitHub ↗
(file_path, filter_path, filter_key=None, filter_val=None)

Source from the content-addressed store, hash-verified

4
5
6def queryFile(file_path, filter_path, filter_key=None, filter_val=None):
7 back = []
8 data = json.load(open(file_path))
9 if filter_path == ['']:
10 return [data]
11 for key in filter_path: # Get to the point
12 data = data.get(key)
13 if not data:
14 return
15
16 if type(data) == list:
17 for row in data:
18 if filter_val: # Filter by value
19 if row[filter_key] == filter_val:
20 back.append(row)
21 else:
22 back.append(row)
23 else:
24 back.append({"value": data})
25
26 return back
27
28
29# Find in json files

Callers 1

queryFunction · 0.85

Calls 2

loadMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected