VulpesOS/gaia/test_media/reference-workload/readJSON.py
OverSu b38dea0597 Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
2026-09-30 23:13:03 +02:00

33 lines
667 B
Python
Executable file

#!/usr/bin/python
#
# This script parses json files, and extracts a value from a provided key
# The value is printed to stdout
import json
import os
import sys
json_data=open(sys.argv[1])
data = json.load(json_data)
json_data.close()
keyString = sys.argv[2]
keys = keyString.split('/')
result = data
matchedKey = ""
for key in keys:
if key.endswith("*"):
matchKey = key.rstrip("*")
for eachKey, eachValue in data.items():
if eachKey.startswith(matchKey):
result = result[eachKey]
matchedKey = eachKey
break
else:
result = result[key]
if matchedKey == "":
print result
else:
print matchedKey + "/" + str(result)