Refine the JSON output

Should throw err first when err exists.