Added most of JSON communication code.