Dataset WRITE-JSON to JsonObject

Posted by Mike Fechner on 02-Jun-2016 09:20

The READ-JSON method of the Dataset handle is able to read directly from a JSON object. But WRITE-JSON cannot write to a JsonObject. Is there a reason why that is not available? Or is it available and just not documented? Is there another way to do that (that does not require going via a LONGCHAR)?

All Replies

Posted by Robin Brown on 02-Jun-2016 09:51

You might see this twice.  I replied to the e-mail and it hasn't shown up here yet.

Hi Mike,

No this is not currently possible. I know we have discussed this within the coreclient team.  If it is not on our roadmap, then we should put it there.

Regards,

Robin

Posted by Mike Fechner on 02-Jun-2016 09:55

I see that as a huge limitation - especially now with the new Pacific  Web Speed capabilities. So it should definitively be on the roadmap.

Posted by Peter Judge on 02-Jun-2016 10:40

EDIT: ooops, reading the wrong way. It's the ability to have a Write(DATASET-HANDLE) that you want.

Have you looked at the Read() method on the JsonObject?

Read( INPUT DATASET-HANDLE pds-handle )

Read( INPUT DATASET-HANDLE pds-handle,
      INPUT omit-initial-values AS LOGICAL )

Read( INPUT DATASET-HANDLE pds-handle,
      INPUT omit-initial-values AS LOGICAL,
      INPUT read-before-image AS LOGICAL)

Read( INPUT TABLE-HANDLE tt-handle )

Read( INPUT TABLE-HANDLE tt-handle,
      INPUT omit-initial-values AS LOGICAL )

Read( INPUT buffer-handle AS HANDLE )

Read( INPUT buffer-handle AS HANDLE,
      INPUT omit-initial-values AS LOGICAL )

Posted by Evan Bleicher on 02-Jun-2016 11:42

Hi Mike:

This feature has been added to the backlog / roadmap.

Posted by Mike Fechner on 03-Jun-2016 00:43

Hi Peter, no I have missed that. Will test that. I looked at the ObjectModelParser as that seemed the right place for such functionality. So I'm glad, I'm not the only one who wasn't aware of that :-)

Evan, anyway, I believe a WRITE-JSON option would be helpful and consistent.

Thanks anybody!

Posted by Mike Fechner on 03-Jun-2016 07:49

Just for the record - Peter's method works from 11.4 on.

Posted by Robin Brown on 06-Jun-2016 11:51

Hi Mike,
 
No this is not currently possible. I know we have discussed this within the coreclient team.  If it is not on our roadmap, then we should put it there.
 
Regards,
Robin
 

Posted by Peter Judge on 09-Jun-2016 15:26

It happens I just have a need to do this. I ended up with this approach:

	        when type-of(pData, JsonConstruct) then
	        do:
	            cast(pData, JsonConstruct):Write(mData).
	            
	            /* can never be */
	            if type-of(pData, JsonArray) then
	            do:
	                create temp-table hData.
    	            hData:read-json(DataTypeEnum:Memptr:ToString(), mData).
	            end.
	            else
	            do:
	                create dataset hData.
	                hData:read-json(DataTypeEnum:Memptr:ToString(), mData) no-error.
	                if error-status:error then
	                    delete object hData.

                    if not valid-handle(hData) then
                    do:
                        create temp-table hData.
                        hData:read-json(DataTypeEnum:Memptr:ToString(), mData) no-error.
                        if error-status:error then
                            delete object hData.
                    end.
                end.
                
                if valid-handle(hData) then
                do:
                    this-object:Write(hData).
                    cast(this-object:Value, WidgetHandle):AutoDestroy = true.
                end.
            end.    /* JSON */

Posted by anbuselv on 22-Jul-2019 19:11

Hi Team,

Still the feature of WRITE-JSON METHOD not available for jsonobject ? .. , READ method of JsonObject helps what we need.

Progress knowledge has some details and example for WRITE-JSON related to JsonObjecy and JsonArray , may be needs correction?

documentation.progress.com/.../index.html

Thanks in advance!

-Anbu

This thread is closed