Improved and Fixed static json_encode function