Removing dependency on json_encode