Refactor process and output to json