Revised according to new json ret value. Added getLastError function in case of an error.