Created
July 5, 2021 19:27
-
-
Save quiye/9d567ec18b01c4cb614f4d1728b961db to your computer and use it in GitHub Desktop.
json arg searcher
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from typing import Dict, List, Any | |
import sys | |
if len(sys.argv) != 2: | |
raise Exception("invalid args") | |
id = sys.argv[1] | |
def check(name: str, a: Any, isPrintable: bool = False, path: str = "") -> None: | |
if isinstance(a, dict): | |
for k, v in a.items(): | |
if k == name: | |
check(name, v, True, path+"."+str(k)) | |
else: | |
check(name, v, isPrintable, path+"."+str(k)) | |
elif isinstance(a, list): | |
for i in a: | |
check(name, i, isPrintable, path+'[]') | |
elif isPrintable: | |
print(path + '.' + str(a)) | |
elif str(a) == name: | |
check(name, a, True, path) | |
for line in sys.stdin: | |
a = json.loads(line) | |
check(id, a) |
Author
quiye
commented
Jul 5, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment