I would like to create the following JSON object in ESQL and put it on the SET OutputRoot.JSON.Data. How do I do that?
{
"active" : [ {"name" : "test"},
{"name": "test2"}]
"inactive" : [ {"name" : "test3"}]
}
There is a standard procedure for IIB developers who want to output a specific format of XML/JSON:
Use a text editor to create the document that you want to output
Create a simple message flow that parses that document.
On the FileInput node (or HTTPInput, if you prefer) set the Domain to 'JSON'
Make sure that the second node is a Trace node with Pattern set to '${Root}'.
Put the example JSON through the message flow
Examine the Trace node output, paying special attention to the field type on each node
Write ESQL that produces an identical message tree under OutputRoot.JSON.Data
The below snippet demonstrates how to create JSON you need:
CREATE FUNCTION Main() RETURNS BOOLEAN
BEGIN
-- Create JSON domain
CREATE LASTCHILD OF OutputRoot DOMAIN 'JSON' NAME 'JSON';
-- Create root Data field
CREATE FIELD OutputRoot.JSON.Data;
DECLARE OutMsg REFERENCE TO OutputRoot.JSON.Data;
CREATE FIELD OutMsg.active IDENTITY (JSON.Array)active;
SET OutMsg.active.Item[1].name = 'test';
SET OutMsg.active.Item[2].name = 'test2';
SET OutMsg.(JSON.Array)inactive.Item[1].name = 'test3';
RETURN TRUE;
END;
Also you can read more information about work with JSON here Manipulating messages in the JSON domain and here Creating or transforming a JSON message by using a message map
Related
I need to consume and parse incoming json from a third party system in my code. I used RestTemplate to do it. So the response from the system looks like below.
{ "data": { "05AAAFW9419M11Q": { "gstin": "05AAAFW9419M11Q", "error_cd": "SWEB_9035", "message": "Invalid GSTIN / UID" } } }
Now the problem is the property name ("05AAAFW9419M11Q" in this case) in dynamic and in the next response it would be another string. In this case, how can I parse this json as this is not fixed in Oracle Integration Cloud? Response wrapper is not capturing the data apart from the one that is used for configuring the adapter which is fair enough as fieldname itself is changing.
Is there is any workaround for this?
You will have to go to PL/SQL and dynamic SQL, and if it's always the value of gstin entry, you can get the path of the key with
select '$.data.' ||
json_query(js_column, '$.data.*.gstin') into v_key path from table_with_json_column where ... conditions... ;
(assuming there is only 1 "data" per JSON payload) to later build a dynamic query based on json_table.
I wish to create notification message which needs to have the name of the recipient and some other values calculated in the notification activity script in a workflow. How do I use them inside the message body?
Hmm, would it make sense to just create an event where you include the values you need into one of the parameters? Then in the notification you can access the parameters and parse the values in anyway you want.
Something like:
var jsonstr = '[{'name' : 'value'}, {'name' : 'value2'}, {'name' : 'value3'}]';
gs.eventQueue('my.event.example', current, jsonstr, '');
Just make sure that the parameter is a string. You can create a JSON, convert that into a string and then parse that in your email script.
Can someone please help me, how to execute bulk insert with header "Content-Type: application/x-ndjson" in elastic4s ? I have tried this
client.execute {
bulk(
indexInto("cars" / "car").source(getCarsFromJson)
).refresh(RefreshPolicy.WaitFor)
}.await
It works for one element in json, but when i add another element to json, no element are added to elastic.
Are you sure you are using the right syntax? Shouldn't it say
"cars/car"
Instead of
"cars" / "car"
The source method on indexInto will not support multiple json objects, because you're trying to put multiple documents inside a single document insert.
Instead, you will need to take your json, parse it into objects, and iterate over them adding an insert document for each one.
Something like the following:
def getCarsFromJson: Seq[String] = /// must return a sequence of json strings
val inserts = getCarsFromJson.map { car => indexInto("cars" /"car").source(car) }
client.execute {
bulk(inserts:_*).refresh(RefreshPolicy.WaitFor)
}
I am currently using this:
params["RPBla"].join(",")
as default parameter of a (stored procedure) dataset. This works fine and sends one or more selected values from the report parameter RPBla to a stored procedure, e.g.:
1,2,3
Unfortunately, this does not work if the user does not select any value. Any ideas what to do. Actuate BIRT should send NULL instead of for example 1,2,3.
What about testing the content in this default value expression, something like:
if (params["RPBla"].value==null){
null;
}else{
var list=params["RPBla"].join(",");
list.length>0 ? list : null;
}
Of course you could return anything you need instead of "null" here, for example returning a specific value warning the stored procedure that the filter should be disabled.
I'm trying to create a Restful service that will return JSON or XML data. The company is using Oracle application express (Restful Services) as the tool for the job.
I've noticed that the latest versions of Application Express the XML option is no longer.?
I was wondering does anyone one have any examples or ideas on how I can can create a Restful service that will return JSON or XML depending on the content type I request ?
I'm currently running Application Express 4.2.5.00.08.
This has always been pretty straight forward in other languages but I need to work it out with oracle data services ORDS
The current setup I have tried is to define a Restful service as follows ;
Resful Service Module :
URI Template : test
Method : GET
Source : Query Format : JSON (XML is no longer option)
Require Secure Access : NO
Source :
SELECT RESTful_Testing.GetSampleData(:contentType) FROM DUAL
Parameters
Name : Accept
Bind Variable Name : contentType
Access Method : IN
Source Type : HTTP Header
Parameter Type : String
I have set it up so I can call an Oracle Package and pass in the content type. The problem I have is that the format is already predefined, so any attempt to return XML would be incorrect ( or can I alter the header later).
The Package Code is Very basic and is as follows just for testing ;
CREATE OR REPLACE PACKAGE APEX_EDS.RESTful_Testing AS
TYPE resultCursor IS REF CURSOR;
function GetSampleData(contentType VARCHAR) return resultCursor;
END RESTful_Testing;
/
CREATE OR REPLACE PACKAGE BODY APEX_EDS.RESTful_Testing AS
function GetSampleData(contentType VARCHAR) return resultCursor AS
O_resultCursor resultCursor;
BEGIN
-- Check the Content Type
IF ( contentType = 'application/xml' ) THEN
OPEN O_resultCursor FOR
select '<ROOT><NAME>John</NAME><SURNAME>Smith</SURNAME>
<CONTENT_TYPE>application/xml</CONTENT_TYPE></ROOT>' FROM DUAL;
return(O_resultCursor);
ELSE -- Assume JSON so return normal
OPEN O_resultCursor FOR
select 'John' FirstName, 'Smith' Surname, contentType ContentType FROM DUAL;
return(O_resultCursor);
END IF;
END;
END RESTful_Testing;
Hope that further adds to my issue and hope there are some oracle ORDS experts out there :).
We are currently doing this on a project with apex. You should be able to find lots of tutorials online. E.g. http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/apex/r42/RESTful_WS_oll/RESTful_WS_oll.html
You can change the type of rest service to return JSON in the example above, but not XML. However it's fairly straightforward with the various xml functions in sql e.g. http://docs.oracle.com/cd/B19306_01/appdev.102/b14259/xdb13gen.htm#i1029583
I'm sure if you can get your restful services hooked up you should also be able to create a service to return a custom result which you can get from an xml query.
The closest I get is by trying to manually set the output. I determine the content type to be returned from looking what the accept header is being sent by the request.
begin
IF (:contentType = 'application/xml') THEN
--set the response format
owa_util.mime_header('application/xml', true, 'ISO-8859-4');
htp.p('<?xml version="1.0" encoding="UTF-8" ?>');
htp.p('<ROOT>');
htp.p('<NAME>');
htp.p('JOHN');
htp.p('</NAME>');
htp.p('<SURNAME>');
htp.p('SMITH');
htp.p('</SURNAME>');
htp.p('<CONTENT_TYPE>');
htp.p(:contentType);
htp.p('</CONTENT_TYPE>');
htp.p('</ROOT>');
ELSE
owa_util.mime_header('application/json', true);
--quick json here will need to use library to parse query
-- http://sourceforge.net/projects/pljson/ used for real data
htp.p('{"name" : "John" , "surname" : "smith", "content_type" : ' || :contentType || '}');
END IF;
end;
It shows that it can be done but I still would like to here from people out there if there is a more elegant solution.
Thanks
Neil