1. Michael Bestikov
  2. PowerBuilder
  3. Monday, 31 May 2021 12:05 PM UTC

HELLO FRIENDS 

I NEED TO SERIALIZE  SQL SELECT / DW   TO JSON STRING  IN PB CLASSIC 2019

THANKS 

Daryl Foster Accepted Answer Pending Moderation
  1. Tuesday, 1 June 2021 00:30 AM UTC
  2. PowerBuilder
  3. # 1

Hi Michael,

If you are wanting to create json from a select statement and you use MS SQL Server, have a look at the "FOR JSON" functionality of SQL Server.  https://docs.microsoft.com/en-us/sql/relational-databases/json/format-query-results-as-json-with-for-json-sql-server?view=sql-server-ver15

It takes a bit of getting used to, but once you get the hang of it you can create very complex json directly in your select statement. I've been using it quite a bit lately and it saves me from building the json with JSONGenerator. I usually add the select statement with one column called "json_data" to a datawindow and use the datawindow to retrieve it.

JSONGenerator is still useful, so it depends on your use case.  In other code I've created some parts of my json with "FOR JSON" and some parts with JSONGenerator and pieced them together with JSONPackage.

The datawindow control also has an ExportJSON function (which I haven't used) to export the contents of the datawindow columns to a json string.

So, there are a heap of ways to do it, it probably depends on exactly what the json looks like that you are trying to create.

Comment
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Monday, 31 May 2021 14:11 PM UTC
  2. PowerBuilder
  3. # 2

Hi Michael;

   Have a look at the JSONGenerator object class in PB for that task.

Regards .... Chris

Comment
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.