[Progress Communities] [Progress OpenEdge ABL] Forum Post: RE: jsonObject and raw data-type

Status
Not open for further replies.
F

frank.meulblok

Guest
When a RAW field gets written out to with WRITE-JSON, it gets base64-encoded. READ-JSON into a known schema will base64-decode the data if a JSON element mnaps to a RAW field. Following from that, as long as both your datasets have the same schema the RAW field in both datasets should have the same content. If the schemas don't match, outcomes will vary. If you are creating a new dynamic dataset and let the READ-JSON generate the schema, you are guaranteed to have a schema mismatch. The parser sees a quoted string, and creates a CHARACTER field for it because it doesn't have anything to go on to make a better decision. (And the JSON format doesn't support any metadata to make it more intelligent either). Some examples to prove the above: DEFINE TEMP-TABLE ding NO-UNDO FIELD ding AS RAW. DEFINE TEMP-TABLE dong NO-UNDO SERIALIZE-NAME "ding" FIELD ding AS CHARACTER. DEFINE VARIABLE lcding AS LONGCHAR NO-UNDO. CREATE ding. PUT-INT64(ding.ding,1) = 123467890. TEMP-TABLE ding:WRITE-JSON("longchar",lcding). FIND FIRST ding. DISPLAY length(ding.ding) lcding VIEW-AS EDITOR LARGE SIZE 50 BY 10 length(lcding,"RAW") WITH FRAME X. EMPTY TEMP-TABLE ding. TEMP-TABLE ding:READ-JSON("longchar",lcding). FIND FIRST ding. MESSAGE length(ding.ding) GET-INT64(ding,1). TEMP-TABLE dong:READ-JSON("longchar",lcding). FIND FIRST dong. MESSAGE length(dong.ding). DEFINE VARIABLE hding AS HANDLE NO-UNDO. CREATE TEMP-TABLE hding. hding:READ-JSON("longchar",lcding). hding:DEFAULT-BUFFER-HANDLE:FIND-FIRST(). MESSAGE hding:DEFAULT-BUFFER-HANDLE:BUFFER-FIELD("ding"):DATA-TYPE length(hding:DEFAULT-BUFFER-HANDLE:BUFFER-FIELD("ding"):buffer-value,"RAW").

Continue reading...
 
Status
Not open for further replies.
Top