refactor parsing of json; replace switch statements with generators in an object literal