Factor out some stuff for the json call. See #5