ORDS: Removing escaping char from json in ORDS OUT param - sql

I am using the OUT parameter in the ORDS parameters to send a response which is already in JSON and this stored as CLOB in the DB. When I send this out in the response from the ORDS, ORDS is actually adding lot of back spaces to the response.
Can someone help me to understand how I can remove the escaping chars here(all the backslashes). I had tried a different approach explained by Jeff in another thread to try to use an alias for the JSON key, but it did not work for me.
Over here I have mentioned the response as OUT parameter in my code.
eg payload:
{
"response": "{\n\"Order\":{\n\"OriginalShipmentID\":1\n,\"orderNumber\":1\n,\"orgID\":1\n,\"orderShipmentNumber\":1\n,\"oracleShipSet\":\"1\"\n,\"OeHeaderId\":1\n,\"GsHeaderId\":1\n,\"CustomerPoNumber\":\"1\"\n,\"PaymentTerms\":1\n,\"FreightTerms\":\"PAID\"\n,\"CurrencyCode\":\"USD\"\n,\"BillToSiteUseID\":1\n,\"ShipToSiteUseID\":1\n,\"SalesChannel\":\"DIRECT\"\n,\"HeaderKeyCode\":\"1 1\"\n,\"OrigSysDocumentRef\":\"1\"\n,\"OrderTypeCode\":\"XYZ yXYZ\"\n,\"OrderTypeID\":1\n,\"SalesRepID\":-3\n,\"IsAtgOrder\":\"N\"\n,\"OrderSource\":\"MCP\"\n,\"OdiDocSet\":\"PO\"\n,\"CsServiceSymbol\":\"XYZ\"\n,\"CsServiceFriendlyName\":\"XYZ\"\n,\"CsShipper\":\"NDC_MX\"\n,\"GsShipToAddressID\":1\n,\"GsBillFrtAddressID\":-1\n,\"BillingMethod\":\"DoNotBillFreight\"\n,\"ReasonForNoInvoice\":\"NA\"\n,\"ShippedBy\":\"NA\"\n,\"ManifestID\":1771748\n,\"IsVoided\":\"N\"\n,\"CustomerNumber\":\"1\"\n,\"OrderLines\":[\n]\n,\"HeaderShortNotes\":{\n}\n}\n}\n"
}
Some more details:
SELECT get_json ( :ordernumber,
:warehouseid,
:shipset,
:ordershipmentno,
:gsshipmentid,
:countrycode,
:shipperid,
:fromcurrency,
:tocurrency,
:groupid,
:optionvalues,
:linehaul,
:servicename,
:sigid,
:lineid,
:customerid) "{}Order"
INTO l_response_clob
FROM DUAL;
This function returns a CLOB with a JSON format data and l_response_clob is defined as STRING output parameter on the ORDS.
Essentially, I want to stop ORDS from again converting JSON to JSON.
Been banging head over this from some time but can't seem to make it work.
Thanks for the help I can get here.

Related

unable to convert raw data to json format after replacing the \(slash)

I am passing the raw data and removing unwanted slash and trying to convert to json format, unable to proceed.
json spot = {"LoginDetails":"{\"firstName\":\"abcd\",\"lastName\":\"\",\"middleName\":\"\",\"phoneNumber\":\"6944000000\",\"phoneCountryCode\":\"+91\",\"dob\":\"1945-02-22\"}"}
string a = spot
def ab = a.replace("\\", "")
json st = ab
And request st
When method POST
Then status 200
Getting error
net.minidev.json.parser.ParseException: Unexpected token f
How to resolve this issue and convert the above payload into json format?
NOTE: After conversion to json firstname, phonenumber should be passed dynamically from the preceding API calls.
If u want escape slash with json, you could try
a.replaceAll("\\", "\\\\")
or change it to unicode.
a.replaceAll("\\", "\u005C")
Both of them is workable for browser but not sure for karate, maybe you need change a bit by yourself.

how to pass multiple type of data to API from server side as formdata?

I want to create circuit (messenger like skype) conversation from my server side code (C#) by calling circuit api.
Function : https://circuitsandbox.net/rest/v2/conversations/
I have to pass two type of parameters :
1) Participants - string array
2) topic - string
According to function definition (in swagger), I have to pass them as formdata. But, when I am trying to encode the parameters
var content = new FormUrlEncodedContent(values);
It is not accepting the array string for participants list. It is expecting "key/value" pair as "string/string".
I have even tried to create the JSON serialization also
JsonConvert.SerializeObject(values)
But the API definition is not accepting this converted values as it is expecting formdata in string/string as key/value.
I had even tried to concatenate the participants list with ";" as delimiter. But in that case, I am getting 400 error.
I tried to convert my parameters like this also
var formData = new List>();
formData.Add(new KeyValuePair("participants", JsonConvert.SerializeObject( participants)));
formData.Add(new KeyValuePair("topic", "Testing1"));
But again, I a getting 400 error.
Here is my API call
var response = client.PostAsync("https://circuitsandbox.net/rest/v2/conversations/group", content);
Can someone provide me some code snippet to pass that this data to API?
Let me emphasis, I am trying from server side code (C#) and not jquery code.
as we checked together earlier today, make the participants value a comma separated string of emails and it should work

How to Extract the value of resultSet returned from JDBC response (Via MEL) Mule ESB

I have JDBC where I'm calling the stored Procedure, It is returning the response as below, But I'm pretty not sure how to extract the value of result set
Please find the response from DB
{updateCount1=4,resultSet1=[{XML_F5RYI-11YTR=<Customers><Customer1>John<Customer1><Customer2>Ganesh<Customer2><Customers>}],resultSet2[{SequenceNumber=94}],updateCount2=1, updateCount3=4}
I have used the this expression #[message.payload.get(0)], It has return the ResultSet as below, But not exactly value required. I need to take the xml value of XML_F5RYI-11YTR.
{XML_F5RYI-11YTR=<Customers><Customer1>John<Customer1><Customer2>Ganesh<Customer2><Customers>}
Also tried like below
#[message.payload.get(0).XML_F5RYI-11YTR] but getting error , not able to extract the xml.
Could you please suggest how can I extract the xml from the ResultSet1
In most cases, the way you did it should work. I think what is happening here is that the hyphen in the column name is interpreted by the MEL parser as a subtraction. So you could change yours to this syntax, and it should work:
#[message.payload.get(0)['XML_F5RYI-11YTR']]
Also you can omit "message", as payload is resolvable directly:
#[payload.get(0)['XML_F5RYI-11YTR']]
You could use array bracket syntax to access the first row in the result set, instead of the get method:
#[payload[0]['XML_F5RYI-11YTR']]
Finally, you might want to do something for each row returned from the database. If you use a collection-splitter or a for-each, your payload will be the map that represents the row, instead of a list of maps representing the whole result set:
<collection-splitter />
<logger message="#[payload['XML_F5RYI-11YTR']]" />
EDIT
To access the result set in the payload shown in the question, you would need to access it like so:
#[payload.resultSet1[0]['XML_F5RYI-11YTR']]
The database connector gives you a list of maps. The map keys will be the name of the columns. Therefore if you want to get updateCount1, you can use something like this:
#[payload.get('updateCount1')]"
Thump rule - you database connector gives you list of map, not sure what format does it is carry, if you want XML_F5RYI.. value then do the below
[message.payload.get(0)] convert it to json or map from which #[message.payload.get("XML_F5RYI-11YTR")]

How to store a Japanese Character in json_encode?

I'm trying to save a json_encoded strings to the database but whenever i do i get this:
u30abu30bf
when saving:
カタ
how do i decode such a thing?
tried php utf8_decode and encode but i doesn't seem to work,
i also tried reading the threads below:
PHP decoding and encoding json with unicode characters
difficulty passing Japanese characters(UTF-8) via json_encode
here is a var_dump data of $flex_encoded before passing it as a parameter:
//this one seems to passing the right encoding
[{"japanese_name":"\u30ca\u30ab\u30cd"},{"japanese_name":"\u30ca\u30ab\u30cd"}]
here is the function call:
$this->updateFlexData($game_id, $flex_encoded);
here is the function for updating my db:
function updateFlexData($game_id, $json_data)
{
$arrVal = array(
'json_data'=> $json_data,
);
Db::getInstance()->autoExecute('japanese_names', $arrVal, 'UPDATE', " game_id = '".$game_id."'", false);
}
database column type is:
`json_data` longtext CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
my PHP version:
PHP Version 5.3.10
Try JSON_UNESCAPED_UNICODE
json_encode($data, JSON_UNESCAPED_UNICODE);
And instead of this \u7537\u6027\u304c\u5f7c\u5973\u306b\u7740\u3066\... you're going to get 男性が彼...
after hours of tinkering with the code i somehow made it to work:
ok its maybe not the solution but:
when i proceed to storing json_data with this content(below) decoding json_data from database results to parse error because of the extra " quotations
$japanese_name = json_encode($japanese_text); //returns "\u30ca\u30ab\u30cd"
i just removed the " from each sides to make it just \u30ca\u30ab\u30cd and then proceeded to store in the db
$jp = str_replace("\"","",$japanese_name); //returns \u30ca\u30ab\u30cd

strip_tags with json data went wrong

When I strip html tags with strip_tags in rails of the json data,it returns the wrong data:
the original data is: "<p><em><span style=\"font-size: 96px; \">test</span></em></p>"
data.to_json is: "\"<p><em><span style=\\\"font-size: 96px; \\\">\\u9ed1\\u4f53\\u5b57\\u54e6</span></em></p>\""
the stripped data that after strip_tags is: "\""
Who can tell me the reason or other solutions?
Change the order to :
strip_tags(data).to_json
You will get "test" as expected.
The reason is being html-scanner (used by strip_tags) strips the encoded "test" value.