Skip to Main Content

APEX

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Adding a JSON (CLOB) object to another in APEX_JSON

Nicke KOct 24 2019 — edited Oct 28 2019

Hi,

I'm trying to write a wrapper-function with APEX_JSON (Apex 5 on a 11gR2) for my database calls that act as backend-methods for some REST-calls. I have something like

function ok(message  varchar2, payload clob)

which uses APEX_JSON for generating something like

{

  "level" : "INFO",

  "message" : -- message here,

  "payload" : -- payload here

}

The problem is that my payload is also a JSON object (usually a sys_refcursor passed to APEX_JSON) and a haven't found a good way of adding my payload to the outer object.

If I do a plain APEX_JSON.write, the payload object is escaped so my " become \" and break in deserialization

If I do a APEX_JSON.parse on the payload object, the quotes are fine but special characters become unicode, again breaking deserialization

What would be  a proper way of adding my payload so I don't get any extra escaping etc? So that a payload of

[

{

   "name" : "åäö"

},

{

   "name" : "öäå"

}

]

after merging would just be

{

  "level" : "INFO",

  "message" : "here you go",

  "payload" :

  [

    {

      "name" : "åäö"

    },

    {

      "name" : "öäå"

    }

  ]

}

And not have any escaped unicode or \" in strange places. Unescaped unicode is fine since Java converts them automagically on the other size

I thought of just adding some sort of "payload" : *PAYLOAD* and then do a search/replace but since the payload can be quite large (and is in a CLOB), I would prefer not to...

Thanks in advance,

  Nik

Comments
Post Details
Added on Oct 24 2019
3 comments
1,582 views