Skip to content

Instantly share code, notes, and snippets.

@britishben
Created December 12, 2017 12:46
Show Gist options
  • Save britishben/8d8ddd9d9f647e0407e8b312041c501a to your computer and use it in GitHub Desktop.
Save britishben/8d8ddd9d9f647e0407e8b312041c501a to your computer and use it in GitHub Desktop.
Returns a single field from a json textfile - The example I use has the format {"msg":{"key":"value",...}}
#Usage: jsonread.py <json_filename> <field>
import json
import sys #just for arguments
from pprint import pprint
with open(sys.argv[1]) as data_file:
data=json.loads(data_file.read())
pprint(data['msg'][sys.argv[2]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment