#!/usr/bin/env python # Loads json into a python datastructure from a url # Usage: curljson http://example.com/json_endpoint # Then the datastructure is accessible via jobj import json import sys from IPython import embed from subprocess import Popen, PIPE def load_jobj(*args): if len(args) == 1: args = args[0].split() if args[0] != 'curl': args = ['curl'] + args if len(args) > 1 and args[1] == 'curl': args.pop(1) p = Popen(args, stdout=PIPE, stderr=PIPE) stdout, stderr = p.communicate() if stderr: print print stderr return json.loads(stdout) if __name__ == "__main__": args = list(sys.argv) args[0] = 'curl' jobj = load_jobj(*args) print "="*50 print "The json is loaded as 'jobj'. Have at it boss" print "="*50 embed()