Parsing JSON flexibly and a map/reduce function