Added URL encoding option and return JSON error