Question How Make Json Out Of One Tt/ds Record At A Time.

jay123035

New Member
I have a program that takes a temp-table, reads it into a json object then uses that Json to call a rest service i need to tweak it so that it only sends on record at a time until all the records are sent.

is there anyway to do this dynamically, or do i need to break the data and build the json myself? (i would love an example)

thanks


Code:
DEFINE TEMP-TABLE Cust
  FIELD custid              AS INTEGER
  FIELD test1                AS CHAR
  FIELD test2               AS CHAR
  FIELD test3               AS INTEGER.


PROCEDURE "doJson.ip":

    /* Create new JsonObject */
    oJson = NEW JsonObject().

    /* Fill with properties representing each field in each record of temp-table */
    counter = 0.
    FOR EACH Cust BREAK BY cust.custid.
        IF AVAILABLE cust THEN
        DO:
            counter = counter + 1.
            lReturnValue = oJson:Read( TEMP-TABLE Cust:HANDLE ).
            oJson:Write(lcTest).
            COPY-LOB FROM lcTest TO FILE "/Cust" + STRING(counter) + ".json".

            oRequest = RequestBuilder:pOST(httpUrl, oJson)
            :AcceptJson()
            :Request.
 
             oResponse = ClientBuilder:Build():Client:Execute(oRequest).
             oEntity = oResponse:Entity.
       END.
  END.
 

Cecil

19+ years progress programming and still learning.
I'm not sure if I fully understand what you are asking for but there is the SERIALIZE-ROW function for buffers.

OpenEdge 11.6 Documentation

Sorry if this is not quite what you are looking for.
 
Top