One Quickie

Quick processing of json. (Python->General)
Have a blorb of well-formed json you want to run some quick processing on? I've been using this little python testbed. No error checking or robustness, but real quick to dig in to data.

import json
from sys import argv

# run with the name of the json file to process.

script, filename = argv

with open(filename) as json_file:
    jsoncontents = json.load(json_file)

# how to dig into the json:
upload = jsoncontents["upload"]
metadata = upload["rideMetaData"]
# print("planned ride: %s" % metadata["plannedRideMinutes"])

ridedata = upload["rideData"]

for blurb in ridedata:
    if blurb["t"] == "hrt":
        value = blurb["v"]

borkware home | products | miniblog | rants | quickies | cocoaheads
Advanced Mac OS X Programming book