Fix error message and incorrect variable reference in JSON parser.
Improve error handling and reporting for http requests and json parsing.