Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion Dist/OpenApiJson.pas
Original file line number Diff line number Diff line change
Expand Up @@ -335,11 +335,23 @@ function TJsonWrapper.JsonToJsonValue(const Value: string): TJSONValue;
end;

function TJsonWrapper.JsonValueToJson(Value: TJSONValue): string;
{$IFDEF USEDBX}
var
JsonBytes: TBytes;
{$ENDIF}
begin
{$IFDEF FPC}
Result := Value.AsJSON;
{$ELSE}
Result := Value.ToString;
{$IFDEF USEDBX}
//Result := Value.ToString; does not correctly escape values (eg \)
//see discussion here https://stackoverflow.com/questions/77623475/how-to-convert-tjsonstring-into-string-containing-json
SetLength(JsonBytes, Value.EstimatedByteSize);
SetLength(JsonBytes, Value.ToBytes(JsonBytes, 0)); //ToBytes escapes all real unicode characters which is unnecessary
Result := TEncoding.UTF8.GetString(JsonBytes); //but this is reverted here
{$ELSE}
Result := Value.ToString;
{$ENDIF}
{$ENDIF}
end;

Expand Down