Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Python command line script to JSON parse
#!/usr/bin python
requires simplejson module (
Usage example:
tail -f /var/log/json.log | grep "" | python log.url
"2011.12.14 14:21" ""
"2011.12.14 14:29" ""
import sys
import simplejson as json
for line in sys.stdin:
data = json.loads(line)
args = sys.argv[1:]
if (len(args) > 0):
for param in args:
nested = param.split('.')
value = data.get( nested[0] )
nested = nested[1:]
for key in nested:
value = value.get(key)
print json.dumps( value ),
print ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.