output json; refactor