1. Yiannis Papadomichelakis
  2. PowerBuilder
  3. Thursday, 4 June 2020 15:56 PM UTC

Hi PBers.....!

I recently tested / used the dw.ExportJson() combined with JSONPackage and I am starting to feel that it's time to move on, from restful XML services to JSON. 

What worries me is that I didn't find any way to limit the data exported ExportJson(). Some datawindows contain many columns that I don't want to export, because I want to have smaller payloads and also because I don't want to expose sensitive data.

This is very easy when exporting XML because the datawindow can contain multiple export profiles, and each of them can contain only the columns needed for the specific task.

Using JsonPackage to delete each undesired key, sounds like a nightmare and I feel that I will loose the benefit of speed. 

Am I missing something or do you have any workaround for this problem?

 

 
Accepted Answer
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Thursday, 4 June 2020 17:52 PM UTC
  2. PowerBuilder
  3. # Permalink

Hi Yiannis;

   You are 100% correct in that the XML feature of the DataWindow allows you to configure the elements (columns) that you would like to expose. Whereas the JSON features in PB currently do not have that capability. Its an "All or nothing" approach from a DWO currently. I can foresee though that there would be a great need for this element filtering in the JSON world as well. Please open a Support Ticket for this requirement as an "enhancement" request. A JSON "pane" like we see for the XML schema in the DW Painter should do it IMHO.

   In the mean-time, I am afraid that the only way to export the data elements you require (AFAIK) would be to copy the exported datum (column by column that you need) to another DataStore that has a customized DW Object for the elements your App only needs to export (expose). This would require you though to copy the affected JSON data over to the export DS. A P.I.A. I know, as this would require some PowerScript looping code on your part.

Regards ... Chris

Comment
  1. Yiannis Papadomichelakis
  2. Monday, 8 June 2020 10:24 AM UTC
Thanks Chris!

I just made a feature request for that.

I think if you add an array with the names of the columns you want to export, will solve this problem. It can also provide a way to define the capitalization of the json keys.
  1. Helpful
There are no comments made yet.
Kevin Ridley Accepted Answer Pending Moderation
  1. Thursday, 4 June 2020 19:53 PM UTC
  2. PowerBuilder
  3. # 1

So if I understand what you are trying to do, you have a DW and you want to export a subset of it as JSON.  You want not all of the columns and a limited number of rows.  To limit the rows, if there is any way to filter the data, I'd suggest doing that.  If not, you could setup a datastore (ds1) with the same dataobject and do a RowsCopy for however many rows you want.  That way if you needed to do a loop to process the entire DW and create multiple JSON files, you can.  For the limited columns, create a new DW object with only the columns you want in your JSON.  Then create a new datastore (ds2) with the new dataobject and copy the data one column at a time.  I believe the syntax would be ds2.object.column_name.Primary = ds1.object.column_name.Primary.  Then do the same for the remaining columns.  Once you're done with the columns, then do your ds2.ExportJSON()

 

Hope this helps,

Kevin

 

 

Comment
  1. Yiannis Papadomichelakis
  2. Monday, 8 June 2020 10:27 AM UTC
Thanks Kavin.

I was aware of that, but it requires to create pairs (at least) for each datawindow you want to export, so more datawindows for us to handle. I understand we can also dynamically create datawindow objects, and probably this is want I am going to do, but this is a lot of work if you want to some of your data.
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.