I am currently trying to generate some REST services in Oracle 18c database and one of my requirement is to send the input payload along with the response. But while attaching the input some additional '/' is also getting added along with each " as an escape character. Could you please help me get rid of the same.
Sample code:
DECLARE
p CLOB := '{"name": "John","age" : 29}'; --Input
j json_object_t := json_object_t.parse('{"Response":"Success"}'); --output
BEGIN
j.put('INPUT', p); --attaching input to response
dbms_output.put_line(j.stringify); -- this has additional / in the o/p.
END;
That's because you're adding an attribute with the string value "{"name": "John","age" : 29}". Not the JSON object!
If you want to add an object, you need to convert the string to a json_object_t first. THEN add it to the other document:
DECLARE
p clob := '{"name": "John","age" : 29}'; --Input
j json_object_t := json_object_t.parse('{"Response":"Success"}'); --output
j2 json_object_t := json_object_t.parse(p);
BEGIN
j.put('INPUT1', j2);
j.put('INPUT2', p);
dbms_output.put_line(j.stringify); -- this has additional / in the o/p.
END;
/
{
"Response":"Success",
"INPUT1":{"name":"John","age":29},
"INPUT2":"{\"name\": \"John\",\"age\" : 29}"
}