Browse Source

Update 'get-json-key.py'

master
jstrong 4 years ago
parent
commit
9af9be956d
1 changed files with 5 additions and 3 deletions
  1. +5
    -3
      get-json-key.py

+ 5
- 3
get-json-key.py View File

@@ -5,6 +5,9 @@ USAGE:
[stdin] | ./get-json-key.py [KEY].. [stdin] | ./get-json-key.py [KEY]..


KEY can be a string key (object) or integer index (array), the program will try both KEY can be a string key (object) or integer index (array), the program will try both

Example: `echo '{"abc":[null,{"zzz":"hello world"}]}' | ./get-json-key.py abc 1 zzz` # -> hello world

""" """


import fileinput, sys, json, functools import fileinput, sys, json, functools
@@ -30,10 +33,9 @@ def main(keys: List[str]) -> None:
raise e raise e
print(val) print(val)


if __name__ == '__main__': if __name__ == '__main__':
if len(sys.argv) < 2: if len(sys.argv) < 2:
print(HELP, file=sys.stderr) print(HELP, file=sys.stderr)
sys.exit(1) sys.exit(1)
main(sys.argv[1:])


main(sys.argv[1:])

Loading…
Cancel
Save