jSon_encode como função para Delphi que aceita TDataSet

Fui encarregado de criar um servidor Indy no Delphi 2007 que se comunica com clientes e retorna dados formatados json de bancos de dados baseados em Sql. Alguém do nosso escritório criou um protótipo usando php. E no protótipo eles usam ojSon_encode funcionam extensivamente para retornar os dados das tabelas. Eu queria saber se havia uma função Delphi semelhante que poderia aceitar umaTDataSet parâmetro e retornar dados json formatados corretamente.

Alguém sabe de tal função?

Atualização 12/10/2013 - minha modificação para @ user2748835 resposta:

function jsonencode(mString: String): String;
begin
  result := StringReplace(mString,'''','\''',[rfReplaceAll,rfIgnoreCase]);
  result := StringReplace(mString,'\','\\',[rfReplaceAll,rfIgnoreCase]);
  result := StringReplace(result,crlf,'\n',[rfReplaceAll,rfIgnoreCase]);
  result := StringReplace(result,'"','\"',[rfReplaceAll,rfIgnoreCase]);
  result := StringReplace(result,'/','\/',[rfReplaceAll,rfIgnoreCase]);
  result := StringReplace(result,'#9','\t',[rfReplaceAll,rfIgnoreCase]);
end;

function jSon_encode(aDataset:TDataset):string;
  function fieldToJSON(thisField:TField):string;
  begin
    try
      result := '"'+thisField.fieldName+'":';
      case thisField.DataType of
        ftInteger,ftSmallint,ftLargeint:
          result := result+inttostr(thisField.AsInteger);
        ftDateTime:
          result := result+'"'+formatdatetime('YYYY-MM-DD HH:NN:SS',thisField.AsDateTime)+'"';
        ftCurrency,
        ftFloat:
          result := result + floattostr(thisField.AsFloat);
        ftString :
          result := result + '"'+jsonencode(thisField.AsString)+'"';
        else
      end; // case
      result := result + ','; 
    except
      on e: Exception do begin
        appendtolog('problem escaping field '+thisfield.fieldname);
      end;
    end;

  end; // of fieldToJSON

  function rowToJSON(ds:TDataset):string;
  var
    fieldIx : integer;
  begin
    result := '';
    for fieldIx := 0 to ds.fieldcount-1 do
      result := result + fieldToJSON(ds.Fields[fieldIx]);
    // trim comma after last col
    result := '{'+copy(result,1,length(result)-1)+'},';
  end; // of rowToJSON
begin
  result := '';
  with aDataset do
  begin
    if not bof then first;
    while not eof do
    begin
      result := result + rowToJSON(aDataset);
      next;
    end;
  end;
  //strip last comma and add
  if length(result)>0 then
    result := copy(result,1,length(result)-1);
  result := '['+result+']';
end; // of DSToJSON

questionAnswers(3)

yourAnswerToTheQuestion