title: convert TDataSet results to JSON format
body: <p>Need to achieve a common conversion between TDataset and JSON in C++ Builder, for the realization of data communication and conversion. However, this is difficult for an amateur developer.</p>
  
  <p>I've found this already done in Delphi, but I don't know Delphi, however it seems to be good example. Maybe somebody can convert it to C++ Builder:</p>
  
  <pre><code>unit uDBJson;
  
  interface
  uses
  SysUtils,Classes,Variants,DB,DBClient,SuperObject;
  
  type
  TTableJSon = class
  
  private
      const cstFieldType = 'FieldType';
      const cstFieldName = 'FieldName';
      const cstFieldSize = 'FieldSize';
      const cstJsonType = 'JsonType';
      const cstRequired = 'Required';
      const cstFieldIndex = 'FieldIndex';
  
      const cstCols= 'Cols';
      const cstData= 'Data';
  
  public
      class function JSonFromDataSet(DataSet:TDataSet):string;
      class function CreateFieldByJson(Fields:TFieldDefs;ColsJson:ISuperObject):Boolean;
      class function ImportDataFromJSon(DataSet:TDataSet;DataJson:ISuperObject):Integer;
      class function CDSFromJSon(CDS:TClientDataSet;Json:ISuperObject):Boolean;
      class function GetValue(Json:ISuperObject;const Name:string):Variant;
  
      class function CreateJsonValue(Json:ISuperObject;const Name:string;const Value:Variant):Boolean;
      class function CreateJsonValueByField(Json:ISuperObject;Field:TField):Boolean;
      class function GetValue2Field(Field:TField;JsonValue:ISuperObject):Variant;
  end;
  implementation
  uses TypInfo,encddecd;
  
  { TTableJSon }
  
  class function TTableJSon.CDSFromJSon(CDS: TClientDataSet;
  Json: ISuperObject): Boolean;
  var
  ColsJson:ISuperObject;
  begin
  Result := False;
  if Json = nil then
      Exit;
  CDS.Close;
  CDS.Data := Null;
  
  ColsJson := Json.O[cstCols];
  CreateFieldByJson(CDS.FieldDefs,ColsJson);
  if CDS.FieldDefs.Count &gt;0 then
      CDS.CreateDataSet;
  ImportDataFromJSon(CDS,Json.O[cstData]);
  Result := True;
  end;
  
  class function TTableJSon.CreateFieldByJson(Fields: TFieldDefs;
  ColsJson: ISuperObject): Boolean;
  var
  SubJson:ISuperObject;
  ft:TFieldType;
  begin
  Result := False;
  Fields.DataSet.Close;
  Fields.Clear;
  for SubJson in ColsJson do
  begin
      ft := TFieldType(GetEnumValue(TypeInfo(TFieldType),'ft'+SubJson.S[cstFieldType]));
      if ft= ftAutoInc then 
        ft := ftInteger;
      Fields.Add(SubJson.S[cstFieldName],ft,SubJson.I[cstFieldSize],SubJson.B[cstRequired]);
  end;
  Result := True;
  end;
  
  class function TTableJSon.CreateJsonValue(Json: ISuperObject;
  const Name: string; const Value: Variant): Boolean;
  begin
  Result := False;
  Json.O[Name] := SO(Value);
  Result := True;
  end;
  
  class function TTableJSon.CreateJsonValueByField(Json: ISuperObject;
  Field: TField): Boolean;
  begin
  Result := False;
  if Field Is TDateTimeField then
      Json.O[Field.FieldName] := SO(Field.AsDateTime)
  else if Field is TBlobField then
      Json.S[Field.FieldName] := EncodeString(Field.AsString)
  else
      Json.O[Field.FieldName] := SO(Field.Value);
  Result := True;
  end;
  
  class function TTableJSon.GetValue(
  Json: ISuperObject;const Name: string): Variant;
  begin
  case Json.DataType of
      stNull: Result := Null;
      stBoolean: Result := Json.B[Name];
      stDouble: Result := Json.D[Name];
      stCurrency: Result := Json.C[Name];
      stInt: Result := Json.I[Name];
      stString: Result := Json.S[Name];
  end;
  end;
  
  class function TTableJSon.GetValue2Field(Field: TField; JsonValue:ISuperObject): Variant;
  begin
  if JsonValue.DataType = stNull then
      Result := Null
  else if Field is TDateTimeField then
      Result := JavaToDelphiDateTime(JsonValue.AsInteger)
  else if (Field is TIntegerField) or (Field is TLargeintField) then
      Result := JsonValue.AsInteger
  else if Field is TNumericField then
      Result := JsonValue.AsDouble
  else if Field is TBooleanField then
      Result := JsonValue.AsBoolean
  else if Field is TStringField then
      Result := JsonValue.AsString
  else if Field is TBlobField then
      Result := DecodeString(JsonValue.AsString)    
  
  end;
  
  class function TTableJSon.ImportDataFromJSon(DataSet: TDataSet;
  DataJson: ISuperObject): Integer;
  var
  SubJson:ISuperObject;
  i:Integer;
  iter: TSuperObjectIter;
  begin
  if not DataSet.Active then
      DataSet.Open;
  DataSet.DisableControls;
  try
      for SubJson in DataJson do
      begin
        DataSet.Append;
        if ObjectFindFirst(SubJson,iter) then
        begin
           repeat
             if DataSet.FindField(iter.Ite.Current.Name)&lt;&gt;nil then
               DataSet.FindField(iter.Ite.Current.Name).Value :=
                  GetValue2Field(
                  DataSet.FindField(iter.Ite.Current.Name),
                  iter.Ite.Current.Value);
           until not ObjectFindNext(iter) ;
        end;
        DataSet.Post;
      end;
  finally
      DataSet.EnableControls;
  end;
  end;
  
  class function TTableJSon.JSonFromDataSet(DataSet:TDataSet):string;
  procedure GetFieldTypeInfo(Field:TField;var Fieldtyp,JsonTyp:string);
  begin
      Fieldtyp := GetEnumName(TypeInfo(tfieldtype),ord(Field.DataType));
      Delete(Fieldtyp,1,2);
      if Field is TStringField then
        JsonTyp := 'string'
      else if Field is TDateTimeField then
        JsonTyp := 'integer'
      else if (Field is TIntegerField) or (Field is TLargeintField) then
        JsonTyp := 'integer'
      else if Field is TCurrencyField then
        JsonTyp := 'currency'
      else if Field is TNumericField then
        JsonTyp := 'double'
      else if Field is TBooleanField then
        JsonTyp := 'boolean'
      else
        JsonTyp := 'variant';
  end;
  var
  sj,aj,sj2:ISuperObject;
  i:Integer;
  Fieldtyp,JsonTyp:string;
  List:TStringList;
  begin
  sj := SO();
  
  aj := SA([]);
  List := TStringList.Create;
  try
      List.Sorted := True;
  
      for i := 0 to DataSet.FieldCount - 1 do
      begin
        sj2 := SO();
        GetFieldTypeInfo(DataSet.Fields[i],Fieldtyp,JsonTyp);
  
        sj2.S[cstFieldName] := DataSet.Fields[i].FieldName;
        sj2.S[cstFieldType] := Fieldtyp;
        sj2.S[cstJsonType] := JsonTyp;
        sj2.I[cstFieldSize] := DataSet.Fields[i].Size;
        sj2.B[cstRequired] := DataSet.Fields[i].Required;
        sj2.I[cstFieldIndex] := DataSet.Fields[i].Index;
        aj.AsArray.Add(sj2);
        List.Add(DataSet.Fields[i].FieldName+'='+JsonTyp);
      end;
      sj.O['Cols'] := aj;
  
      DataSet.DisableControls;
  
      DataSet.First;
      aj := SA([]);
      while not DataSet.Eof do
      begin
        sj2 := SO();
        for i := 0 to DataSet.FieldCount - 1 do
        begin
          //sj2.S[IntToStr(DataSet.Fields[i].Index)] := VarToStrDef(DataSet.Fields[i].Value,'');
          if VarIsNull(DataSet.Fields[i].Value) then
            sj2.O[DataSet.Fields[i].FieldName] := SO(Null)
          else
          begin
            CreateJsonValueByField(sj2,DataSet.Fields[i]);
          end;
        end;
        aj.AsArray.Add(sj2);
        DataSet.Next;
      end;
      sj.O['Data'] := aj;
  
      Result := sj.AsString;
  finally
      List.Free;
      DataSet.EnableControls;
  end;
  
  end;
  
  end.
  
  
  
  
  
  var
  json:TTableJSon;
  s:string;
  
  begin
  
  S := json.JSonFromDataSet(ADODataSet1);
  
  
  
  end;
  
  
  
  var
  json:ISuperObject;
  begin
  json := TSuperObject.ParseFile('json.txt',False);
  TTableJSon.CDSFromJSon(cdsJSON,json);
  end;
  </code></pre>
  
  <p>Here is what I did/got using C++ Builder compiler which translated from pascal to c++, this code:</p>
  
  <pre><code>    // CodeGear C++Builder
      // Copyright (c) 1995, 2016 by Embarcadero Technologies, Inc.
      // All rights reserved
  
      // (DO NOT EDIT: machine generated header) 'uDBJson.pas' rev: 31.00 (Windows)
  
      #ifndef UdbjsonHPP
      #define UdbjsonHPP
  
      #pragma delphiheader begin
      #pragma option push
      #pragma option -w-      // All warnings off
      #pragma option -Vx      // Zero-length empty class member 
      #pragma pack(push,8)
      #include &lt;System.hpp&gt;
      #include &lt;SysInit.hpp&gt;
      #include &lt;System.SysUtils.hpp&gt;
      #include &lt;System.Classes.hpp&gt;
      #include &lt;System.Variants.hpp&gt;
      #include &lt;Data.DB.hpp&gt;
      #include &lt;Datasnap.DBClient.hpp&gt;
      #include "superdate.hpp"
      #include "superobject.hpp"
  
      //-- user supplied -----------------------------------------------------------
  
      namespace Udbjson
      {
      //-- forward type declarations -----------------------------------------------
      class DELPHICLASS TTableJSon;
      //-- type declarations -------------------------------------------------------
      #pragma pack(push,4)
      class PASCALIMPLEMENTATION TTableJSon : public System::TObject
      {
          typedef System::TObject inherited;
  
      private:
          #define cstFieldType L"FieldType"
  
          #define cstFieldName L"FieldName"
  
          #define cstFieldSize L"FieldSize"
  
          #define cstJsonType L"JsonType"
  
          #define cstRequired L"Required"
  
          #define cstFieldIndex L"FieldIndex"
  
          #define cstCols L"Cols"
  
          #define cstData L"Data"
  
  
      public:
          __classmethod System::UnicodeString __fastcall JSonFromDataSet(Data::Db::TDataSet* DataSet);
          __classmethod bool __fastcall CreateFieldByJson(Data::Db::TFieldDefs* Fields, Superobject::_di_ISuperObject ColsJson);
          __classmethod int __fastcall ImportDataFromJSon(Data::Db::TDataSet* DataSet, Superobject::_di_ISuperObject DataJson);
          __classmethod bool __fastcall CDSFromJSon(Datasnap::Dbclient::TClientDataSet* CDS, Superobject::_di_ISuperObject Json);
          __classmethod System::Variant __fastcall GetValue(Superobject::_di_ISuperObject Json, const System::UnicodeString Name);
          __classmethod bool __fastcall CreateJsonValue(Superobject::_di_ISuperObject Json, const System::UnicodeString Name, const System::Variant &amp;Value);
          __classmethod bool __fastcall CreateJsonValueByField(Superobject::_di_ISuperObject Json, Data::Db::TField* Field);
          __classmethod System::Variant __fastcall GetValue2Field(Data::Db::TField* Field, Superobject::_di_ISuperObject JsonValue);
      public:
          /* TObject.Create */ inline __fastcall TTableJSon(void) : System::TObject() { }
          /* TObject.Destroy */ inline __fastcall virtual ~TTableJSon(void) { }
  
      };
  
      bool __fastcall TTableJSon::CDSFromJSon(Datasnap::Dbclient::TClientDataSet* CDS, Superobject::_di_ISuperObject Json)
      {
        ISuperObject *ColsJson;
        bool Result = false;
  
        if(Json == NULL)return Result;
  
          CDS-&gt;Close();
          CDS-&gt;Data = NULL;
  
         ColsJson = Json-&gt;O[cstCols];
         CreateFieldByJson(CDS-&gt;FieldDefs,ColsJson);
         if(CDS-&gt;FieldDefs-&gt;Count &gt;0)CDS-&gt;CreateDataSet();
          ImportDataFromJSon(CDS,Json-&gt;O[cstData]);
         return true;
      }
  
  
      bool __fastcall TTableJSon::CreateFieldByJson(Data::Db::TFieldDefs* Fields, Superobject::_di_ISuperObject ColsJson)
      {
  
        ISuperObject *SubJson;
        TFieldType *ft;
        bool Result = false;
  
        Fields-&gt;DataSet-&gt;Close();
        Fields-&gt;Clear();
  
        // Delphi Pascal code, which I don't know how to convert     
        for SubJson in ColsJson do
  begin
      ft := TFieldType(GetEnumValue(TypeInfo(TFieldType),'ft'+SubJson.S[cstFieldType]));
      if ft= ftAutoInc then 
        ft := ftInteger;
      Fields.Add(SubJson.S[cstFieldName],ft,SubJson.I[cstFieldSize],SubJson.B[cstRequired]);
  end;
        return true;
  
      }
  
      #pragma pack(pop)
  
      //-- var, const, procedure ---------------------------------------------------
      }   /* namespace Udbjson */
      #if !defined(DELPHIHEADER_NO_IMPLICIT_NAMESPACE_USE) &amp;&amp; !defined(NO_USING_NAMESPACE_UDBJSON)
      using namespace Udbjson;
      #endif
      #pragma pack(pop)
      #pragma option pop
  
      #pragma delphiheader end.
      //-- end unit ----------------------------------------------------------------
      #endif  // UdbjsonHPP
  </code></pre>
  
  <p>Please help to translate this code to C++ Builder.</p>
  
  <p>right now I don't know how to translate this piece of code:</p>
  
  <pre><code>for SubJson in ColsJson do
  begin
      ft := TFieldType(GetEnumValue(TypeInfo(TFieldType),'ft'+SubJson.S[cstFieldType]));
      if ft= ftAutoInc then 
        ft := ftInteger;
      Fields.Add(SubJson.S[cstFieldName],ft,SubJson.I[cstFieldSize],SubJson.B[cstRequired]);
  end;
  </code></pre>
  
  <p>All other the missing code of superobject can be found here:
  <a href="https://github.com/hgourvest/superobject" rel="nofollow noreferrer">https://github.com/hgourvest/superobject</a></p>
  
  <p><strong>UPDATE ________________________________________</strong></p>
  
  <p>Below is what I tried to translated from Delphi to C++ Builder, and the only errors I got when tried to compile I have pasted below. Please check this and help to make it correctly translated.</p>
  
  <pre><code>// CodeGear C++Builder
  // Copyright (c) 1995, 2016 by Embarcadero Technologies, Inc.
  // All rights reserved
  
  // (DO NOT EDIT: machine generated header) 'uDBJson.pas' rev: 31.00 (Windows)
  
  #ifndef UdbjsonHPP
  #define UdbjsonHPP
  
  #pragma delphiheader begin
  #pragma option push
  #pragma option -w-      // All warnings off
  #pragma option -Vx      // Zero-length empty class member 
  #pragma pack(push,8)
  #include &lt;System.hpp&gt;
  #include &lt;SysInit.hpp&gt;
  #include &lt;System.SysUtils.hpp&gt;
  #include &lt;System.Classes.hpp&gt;
  #include &lt;System.Variants.hpp&gt;
  #include &lt;Data.DB.hpp&gt;
  #include &lt;Datasnap.DBClient.hpp&gt;
  #include "superdate.hpp"
  #include "superobject.hpp"
  
  //-- user supplied -----------------------------------------------------------
  
  namespace Udbjson
  {
  //-- forward type declarations -----------------------------------------------
  class DELPHICLASS TTableJSon;
  //-- type declarations -------------------------------------------------------
  #pragma pack(push,4)
  class PASCALIMPLEMENTATION TTableJSon : public System::TObject
  {
      typedef System::TObject inherited;
  
  private:
      #define cstFieldType L"FieldType"
  
      #define cstFieldName L"FieldName"
  
      #define cstFieldSize L"FieldSize"
  
      #define cstJsonType L"JsonType"
  
      #define cstRequired L"Required"
  
      #define cstFieldIndex L"FieldIndex"
  
      #define cstCols L"Cols"
  
      #define cstData L"Data"
  
  
  public:
      __classmethod System::UnicodeString __fastcall JSonFromDataSet(Data::Db::TDataSet* DataSet);
      __classmethod bool __fastcall CreateFieldByJson(Data::Db::TFieldDefs* Fields, Superobject::_di_ISuperObject ColsJson);
      __classmethod int __fastcall ImportDataFromJSon(Data::Db::TDataSet* DataSet, Superobject::_di_ISuperObject DataJson);
      __classmethod bool __fastcall CDSFromJSon(Datasnap::Dbclient::TClientDataSet* CDS, Superobject::_di_ISuperObject Json);
      __classmethod System::Variant __fastcall GetValue(Superobject::_di_ISuperObject Json, const System::UnicodeString Name);
      __classmethod bool __fastcall CreateJsonValue(Superobject::_di_ISuperObject Json, const System::UnicodeString Name, const System::Variant &amp;Value);
      __classmethod bool __fastcall CreateJsonValueByField(Superobject::_di_ISuperObject Json, Data::Db::TField* Field);
      __classmethod System::Variant __fastcall GetValue2Field(Data::Db::TField* Field, Superobject::_di_ISuperObject JsonValue);
  public:
      /* TObject.Create */ inline __fastcall TTableJSon(void) : System::TObject() { }
      /* TObject.Destroy */ inline __fastcall virtual ~TTableJSon(void) { }
  
  };
  
  
  
  #pragma pack(pop)
  
  bool __fastcall TTableJSon::CDSFromJSon(Datasnap::Dbclient::TClientDataSet* CDS, Superobject::_di_ISuperObject Json)
  {
    ISuperObject *ColsJson;
    bool Result = false;
  
    if(Json == NULL)return Result;
  
      CDS-&gt;Close();
      CDS-&gt;Data = NULL;
  
     ColsJson = Json-&gt;O[cstCols];
     CreateFieldByJson(CDS-&gt;FieldDefs,ColsJson);
     if(CDS-&gt;FieldDefs-&gt;Count &gt;0)CDS-&gt;CreateDataSet();
      ImportDataFromJSon(CDS,Json-&gt;O[cstData]);
     return true;
  }
  
  
  bool __fastcall TTableJSon::CreateFieldByJson(Data::Db::TFieldDefs* Fields, Superobject::_di_ISuperObject ColsJson)
  {
  
    ISuperObject *SubJson;
    TFieldType ft;
    bool Result = false;
  
    Fields-&gt;DataSet-&gt;Close();
    Fields-&gt;Clear();
  
  
    for(int i = 0; i &lt; ColsJson-&gt;AsArray()-&gt;Length; ++i)
    {
      SubJson = ColsJson-&gt;AsArray()-&gt;O[i]; //&gt;GetO(i);
  
      ft = TFieldType(GetEnumValue(__delphirtti(TFieldType), "ft" + SubJson-&gt;S[cstFieldType]));
  
      if(ft == ftAutoInc)
        ft = ftInteger;
  
      Fields-&gt;Add(SubJson-&gt;S[cstFieldName], ft, SubJson-&gt;I[cstFieldSize], SubJson-&gt;B[cstRequired]);
    }
  
    return true;
  }
  
  bool __fastcall TTableJSon::CreateJsonValue(Superobject::_di_ISuperObject Json, const System::UnicodeString Name, const System::Variant &amp;Value)
  {
    bool Result = false;
  
    Json-&gt;O[Name] = SO(Value);
  
    return true;
  }
  
  
  bool __fastcall TTableJSon::CreateJsonValueByField(Superobject::_di_ISuperObject Json, Data::Db::TField* Field)
  {
    bool Result = false;
  
    if(dynamic_cast&lt;TDateTimeField*&gt;(Field) != 0)
      Json-&gt;O[Field-&gt;FieldName] = SO(Field-&gt;AsDateTime);
    else if(dynamic_cast&lt;TBlobField*&gt;(Field) != 0)
      Json-&gt;S[Field-&gt;FieldName] = Field-&gt;AsString; //EncodeString(..) Field-&gt;AsVariant;  TIdEncoderMIME.EncodeString(m1.Text, IndyTextEncoding_UTF8);  TNetEncoding.Base64.Encode TNetEncoding.Base64.Encode(myString);
    else
      Json-&gt;O[Field-&gt;FieldName] = SO(Field-&gt;Value);
  
      return true;
  }
  
  
  System::Variant __fastcall TTableJSon::GetValue(Superobject::_di_ISuperObject Json, const System::UnicodeString Name)
  {
   switch(Json-&gt;DataType)
   {
      case stNull: return NULL; break;
      case stBoolean: return Json-&gt;B[Name]; break;
      case stDouble: return  Json-&gt;D[Name];  break;
      case stCurrency: return  Json-&gt;C[Name]; break;
      case stInt: return Json-&gt;I[Name]; break;
      case stString: return  Json-&gt;S[Name]; break;
   }
   return NULL;
  }
  
  System::Variant __fastcall TTableJSon::GetValue2Field(Data::Db::TField* Field, Superobject::_di_ISuperObject JsonValue)
  {
  
    if(JsonValue-&gt;DataType == stNull)
      return NULL;
     else if(dynamic_cast&lt;TDateTimeField*&gt;(Field) != 0)
          return JavaToDelphiDateTime(JsonValue-&gt;AsInteger());
     else if (dynamic_cast&lt;TIntegerField*&gt;(Field) != 0 || dynamic_cast&lt;TLargeintField*&gt;(Field) != 0)
          return JsonValue-&gt;AsInteger();
     else if(dynamic_cast&lt;TNumericField*&gt;(Field) != 0)
          return JsonValue-&gt;AsDouble();
     else if(dynamic_cast&lt;TBooleanField*&gt;(Field) != 0)
          return JsonValue-&gt;AsBoolean();
     else if(dynamic_cast&lt;TStringField*&gt;(Field) != 0)
          return JsonValue-&gt;AsString();
     else if(dynamic_cast&lt;TBlobField*&gt;(Field) != 0)
          return JsonValue-&gt;AsString(); //DecodeString(JsonValue.AsString)  //Field-&gt;AsVariant;  TIdEncoderMIME.EncodeString(m1.Text, IndyTextEncoding_UTF8);  TNetEncoding.Base64.Encode TNetEncoding.Base64.Encode(myString);
  
  }
  
  int __fastcall TTableJSon::ImportDataFromJSon(Data::Db::TDataSet* DataSet, Superobject::_di_ISuperObject DataJson)
  {
    ISuperObject *SubJson;
    int i;
    TSuperObjectIter iter;
  
    if(! DataSet-&gt;Active)
      DataSet-&gt;Open();
  
     DataSet-&gt;DisableControls();
  
     try
     {
  
      for(int i = 0; i &lt; DataJson-&gt;AsArray()-&gt;Length; ++i)
      {
        SubJson = DataJson-&gt;AsArray()-&gt;O[i]; //&gt;GetO(i);
        DataSet-&gt;Append();
        if(ObjectFindFirst(SubJson,iter))
        {
           do
           {  if(DataSet-&gt;FindField(iter.Ite-&gt;Current-&gt;Name) != NULL)
               DataSet-&gt;FindField(iter.Ite-&gt;Current-&gt;Name)-&gt;Value =
                  GetValue2Field(
                  DataSet-&gt;FindField(iter.Ite-&gt;Current-&gt;Name),
                  iter.Ite-&gt;Current-&gt;Value);
           }
           while( ! ObjectFindNext(iter));
        }
        DataSet-&gt;Post();
      }
     }
     __finally
     {
      DataSet-&gt;EnableControls();
     }
  }
  
  void GetFieldTypeInfo(Data::Db::TField *Field, String &amp;Fieldtyp, String &amp;JsonTyp)
  {
      Fieldtyp = GetEnumName(__delphirtti(TFieldType),(int)(Field-&gt;DataType));
      Fieldtyp = Fieldtyp.Delete(1,2);
      if(dynamic_cast&lt;TStringField*&gt;(Field) != 0)
        JsonTyp = "string";
      else if(dynamic_cast&lt;TDateTimeField*&gt;(Field) != 0)
        JsonTyp = "integer";
      else if(dynamic_cast&lt;TIntegerField*&gt;(Field) != 0 || dynamic_cast&lt;TLargeintField*&gt;(Field) != 0)
        JsonTyp = "integer";
      else if(dynamic_cast&lt;TCurrencyField*&gt;(Field) != 0)
        JsonTyp = "currency";
      else if(dynamic_cast&lt;TNumericField*&gt;(Field) != 0)
        JsonTyp = "double";
      else if(dynamic_cast&lt;TBooleanField*&gt;(Field) != 0)
        JsonTyp = "boolean";
      else
        JsonTyp = "variant";
  }
  
  
  System::UnicodeString __fastcall TTableJSon::JSonFromDataSet(Data::Db::TDataSet* DataSet)
  {
  
   ISuperObject *sj, *aj, *sj2;
   int i;
   String Fieldtyp,JsonTyp;
   TStringList *List;
  
  
   sj = SO();
   aj = SA(new TVarRec(),0);
   List = new TStringList;
  
   try
   {
      List-&gt;Sorted = true;
  
      for(int i = 0; i&lt; DataSet-&gt;FieldCount - 1; i++)
      {
        sj2 = SO();
        GetFieldTypeInfo(DataSet-&gt;Fields[i].Fields[0],Fieldtyp,JsonTyp);
  
        sj2-&gt;S[cstFieldName] = DataSet-&gt;Fields[i].Fields[0]-&gt;FieldName;
        sj2-&gt;S[cstFieldType] = Fieldtyp;
        sj2-&gt;S[cstJsonType]  = JsonTyp;
        sj2-&gt;I[cstFieldSize] = DataSet-&gt;Fields[i].Fields[0]-&gt;Size;
        sj2-&gt;B[cstRequired]  = DataSet-&gt;Fields[i].Fields[0]-&gt;Required;
        sj2-&gt;I[cstFieldIndex] = DataSet-&gt;Fields[i].Fields[0]-&gt;Index;
        aj-&gt;AsArray()-&gt;Add(sj2);
        List-&gt;Add(DataSet-&gt;Fields[i].Fields[0]-&gt;FieldName+"="+JsonTyp);
      }
      sj-&gt;O["Cols"] = aj;
  
      DataSet-&gt;DisableControls();
  
      DataSet-&gt;First();
      aj = SA(new TVarRec(),0);
      while(! DataSet-&gt;Eof)
      {
        sj2 = SO();
        for(int i = 0; i&lt; DataSet-&gt;FieldCount - 1; i++)
        {
          //sj2.S[IntToStr(DataSet.Fields[i].Index)] := VarToStrDef(DataSet.Fields[i].Value,'');
          if(VarIsNull(DataSet-&gt;Fields[i].Fields[0]-&gt;Value))
            sj2-&gt;O[DataSet-&gt;Fields[i].Fields[0]-&gt;FieldName] = SO(NULL);
          else
            CreateJsonValueByField(sj2,DataSet-&gt;Fields[i].Fields[0]);
        }
        aj-&gt;AsArray()-&gt;Add(sj2);
        DataSet-&gt;Next();
      }
  
      sj-&gt;O["Data"] = aj;
  
      return sj-&gt; AsString();
   }
   __finally
     {
      List-&gt;Free();
      DataSet-&gt;EnableControls();
     }
  
  
  
  }
  
  //-- var, const, procedure ---------------------------------------------------
  }   /* namespace Udbjson */
  #if !defined(DELPHIHEADER_NO_IMPLICIT_NAMESPACE_USE) &amp;&amp; !defined(NO_USING_NAMESPACE_UDBJSON)
  using namespace Udbjson;
  #endif
  #pragma pack(pop)
  #pragma option pop
  
  
  
  #pragma delphiheader end.
  //-- end unit ----------------------------------------------------------------
  #endif  // UdbjsonHPP
  
  [ilink32 Error] Error: Unresolved external 'Udbjson::TTableJSon::' referenced from C:\USERS\USER\DESKTOP\WIN32\DEBUG\UNIT1.OBJ
  [ilink32 Error] Error: Unresolved external '__fastcall Superobject::SA(System::TVarRec *, const int)' referenced from C:\USERS\USER\DESKTOP\WIN32\DEBUG\UNIT1.OBJ
  [ilink32 Error] Error: Unresolved external '__fastcall Superobject::SO(System::UnicodeString)' referenced from C:\USERS\USER\DESKTOP\WIN32\DEBUG\UNIT1.OBJ
  [ilink32 Error] Error: Unresolved external '__fastcall Superobject::SO(System::Variant&amp;)' referenced from C:\USERS\USER\DESKTOP\WIN32\DEBUG\UNIT1.OBJ
  [ilink32 Error] Error: Unresolved external '__fastcall Superobject::TSuperArray::Add(bool)' referenced from C:\USERS\USER\DESKTOP\WIN32\DEBUG\UNIT1.OBJ
  [ilink32 Error] Error: Unable to perform link
  </code></pre>