Add json.swift; refactor json processing code to match