Replace funcking manual json printing by json_encode