improve JSON error handling to fit similar convention