Advice on the use of APEX_JSON with a CLOB in the body as a string

Hello all and thanks for any help in advance.

I have the task of liaising with a 3rd party API via JSON to send information to our database.  First warning is the HOST for us is not and race so I have no way of properly this test until tomorrow, but I wanted to ask this question to try to overcome a potential problem.

In the body of the JSON object, we must add a chunk of xml (already created/kept or can be created on the fly) and it must be validated on as a long string.  Now, this question is that the string can be up to 20000 characters long so when its processed is stored as a CLOB in the database (not made by me).

Now my thoughts early to do this was to create a procedure allowing certain parameters get the relevant piece of data and xml stored as a CLOB.  Then and that's where I maybe need some tips, follow these steps.

This host requires JSON in this format

{

'batchcode': 1234562,

'XML string': 'THIS WILL BE a MASSIVE XML STRING',

""bounding ":" ",".

"ID": "123456465",

'field1 ':

.

.

etc.

}

We currently have a few apex applications so I got a good look at the documentation and allows to generate the required using JSON:

Thus to collect information of input parameters

APEX_JSON. INITIALIZE_CLOB_OUTPUT;

APEX_JSON. OPEN_OBJECT();

APEX_JSON. WRITE ("batchcode," value from database");

APEX_JSON. WRITE ("XML string ', our xml database that is stored as a CLOB string");

APEX_JSON. WRITE (bounding "," value of database");

APEX_JSON. WRITE ('ID', 'Value of database');

.

.

.

etc.

APEX_JSON. CLOSE_OBJECT();

Then validate using endpoint:

APEX_WEB_SERVICE. () MAKE_REST_REQUEST

p_url = > 'URL of the end point. "

p_http_method = > 'MESSAGE ',.

p_username = > API_USER,

p_password = > API_KEY,.

p_body = > apex_json.get_clob_output

);

Now assuming that my method is correct only the APEX_JSON. WRITING literally accept its entry as a type CLOB and he will be able to properly analyze or will it arrive at a mansion that will actually write the string itself?

Edit I found that if I APEX_JSON. WRITE ("XML", "CLOB table column") that it exported the CLOB but not in the format I want.  This is due to the fact that my CLOB has characters like <>etc in II and the output is burning out in unicode, so for example <? XML version = "1.0" encoding = "UTF-8"? "> as stored in the object CLOB becomes \u003C?xml version=\"1.0\ ' encoding =------"UTF - 8\ '? \u003E\n in the output using APEX_JSON. To write.

The only other way to do it, I think it is so divided in pieces as follows:

SELECT ROWNUM as XML_PIECE_NO, TO_CHAR (SUBSTR (a.xmldoc, (ROWNUM-1) * 4000, 4000)) AS SECTION

Of ast_xmldata one

CONNECT (ROWNUM-1) * 4000 < = LENGTH (a.xmldoc)

Then maybe concat in the JSON long xml string field.

I hope I have explained what I want to do but if not please respond any help will be greatly appreciated.

Concerning

Post edited by: K4E

EDIT I CAME FROM WITH a SOLUTION

Post edited by: K4E - found solution 02/04/2016

Thanks for the response of Christian, logical exit that way.

Through some trial and error, I found a solution to my problem that seems effective enough without having to worry about unicode characters written.  There is seemingly a procedure without papers in the APEX_JSON package called apex_json.write_raw that does what it says.  All I had to do then was to use escape characters in my CLOB for things like "then I get a few good valid JSON in the format of the API, I work with love."

Hope this helps someone else with the situation.

K4E

Tags: Database

Similar Questions

Maybe you are looking for