Recent

Author Topic: Dataset to Json  (Read 6122 times)

taqtaq

  • New Member
  • *
  • Posts: 13
Dataset to Json
« on: September 04, 2018, 12:21:28 am »
Hello,
Is there any class or function to convert a dataset to json?

In Delphi you can use DataSetConverter4Delphi (  https://github.com/ezequieljuliano/DataSetConverter4Delphi  )

Is there something like that?

I'm looking for something to convert dataset->json and json->dataset

Thanks


marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11453
  • FPC developer.
Re: Dataset to Json
« Reply #1 on: September 04, 2018, 10:14:15 am »
There is a fpjsondataset unit included with fpc/lazarus. I don't know if it is something similar, but have a look

LuizAmérico

  • Sr. Member
  • ****
  • Posts: 457
Re: Dataset to Json
« Reply #2 on: September 05, 2018, 04:06:32 pm »
https://github.com/blikblum/luipack/blob/master/luicomponents/luijsonutils.pas#L140-L149

Examples:

Result := DatasetToJSON(RequestItemsDataset, [djoSetNull], '');   

or

DatasetToJSON(Query, TJSONArray(ResponseData), ConvertOptions, FOutputFields);

Where FOutputFields is '["id", "name", {"name": "sectorid", "mapping": "wardid"}, "registry", "gender", "birthdate", "admissiondatetime", "bednumber", "cns", "isolationdata"]';

The dbfield wardid will be exported with sectorid name

 

TinyPortal © 2005-2018