Skip to content

JSON Formatting Breaks Due To Comments #48

@8yteWizard

Description

@8yteWizard

To be totally clear I am using the ChatGPT online endpoint and directing it to my locally hosted LM Studio endpoint however this should be irrelevant

Description:
The AI API fails to process code snippets that contain comments (e.g., // This is a comment). This causes the response to fail with a JSON parsing error.

Error Message Response:

Question cannot be answered
Return: {"error":{"message":"Invalid body: failed to parse JSON value. Please check the value to ensure it is valid JSON","type":"invalid_request","code":"invalid_json"}}

!!! Very likely that other syntax and special characters are breaking json format that I have not run into !!!

Reproduction Steps:

  1. Send the following code to the AI:
// GetMachineName retrieves the machine's (computer's) name
function GetMachineName: string;
var
  Buffer: array[0..255] of WideChar; // Buffer to store the machine name
  Size: DWORD;                        // Size of the buffer
begin
  Size := Length(Buffer);
  if GetComputerNameW(@Buffer[0], Size) then
    Result := PWideChar(@Buffer[0])   // If successful, return the machine name
  else
    Result := 'Unknown';              // Return 'Unknown' if failed
end;

Steps To Fix:

  1. Replace "//" characters with something like block comments "{}" automatically:
{ GetMachineName retrieves the machine's (computer's) name }
function GetMachineName: string;
var
  Buffer: array[0..255] of WideChar;
  Size: DWORD;                        { Size of the buffer }
begin
  Size := Length(Buffer);
  if GetComputerNameW(@Buffer[0], Size) then
    Result := PWideChar(@Buffer[0])   { If successful, return the machine name }
  else
    Result := 'Unknown';              { Return 'Unknown' if failed }
end;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions