November 01, 2013

JSON and Siebel


JSON(JavaScript Object Notation) is a new lightweight integration message format which is replacing XML in thin client integrations. There are no meta tags and data description in JSON as in XML, it is just a string representation of JavaScript Object, it is designed to help javascript code to convert data to string and string to data without considerable overhead.


JSON vs XML


Many companies have started replacing XML with JSON in APIs. All the APIs of Google (Maps,Mail,Calendar, plus etc are now serving JSON), Twitter API,  Facebook apps and interfaces are built using JSON.
Read more on JSON on : http://www.json.org/

Siebel lacks in support of JSON on server side. Oracle support recommends use of workarounds such as using custom scripting to parse JSON response received by Siebel.

So how to interpret json in Siebel? Answer lies in the escript engine of Siebel. Siebel eScript as we know is actually ECMA script which was basis of Javascript. That is why the syntax of Javascript and eScript closely matches each other.
ECMA adopted JSON before it became standard in javascript. Thus our well known Siebel eScript also have some support.



ECMA script provide eval method to convert string into an object. This method is also available in Siebel eScript.

From Siebel Tools help:
The Evaluate Expression method evaluates the value that the expression argument contains. It returns the value that it evaluates in the expression argument. If the expression argument is a string, then this method attempts to interpret the string as if it is JavaScript code.

On these lines I wrote small piece of code to test.

function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
var bs = TheApplication().GetService("EAI HTTP Transport");
var inp = TheApplication().NewPropertySet();
var op = TheApplication().NewPropertySet();
inp.SetProperty("HTTPRequestMethod","GET");
inp.SetProperty("CharSetConversion","UTF-8");
inp.SetProperty("HTTPRequestURLTemplate","https://ajax.googleapis.com/ajax/services/feed/find?v=1.0&q=Official%20Google%20Blogs");
bs.InvokeMethod("SendReceive",inp,op);
var temp = op.GetValue();
eval("var json = " + temp);var temp2 = TheApplication().NewPropertySet();
jsonParser(json,temp2);
Outputs.AddChild(temp2);
temp2=null;
return (CancelOperation);
}

function jsonParser(json,ps)
{
for (var prop in json) {if (typeof(json[prop]) == "object") {
var child = TheApplication().NewPropertySet();
jsonParser(json[prop],child)child.SetType(prop);
ps.AddChild(child);
child= null;
}
else{
ps.SetProperty(prop,json[prop]);
}
}
}

This code was able to convert the JSON in to an object and by using some loops it was able to return back the property set representing JSON. It is just a proof of concept code, I need to work on the memory allocation of the recursive function. Looking forward to hear some thoughts from experts.
output of business service

child property set


In case if you are facing difficulty in interpreting the JSON using notepad you can use online viewer : http://jsonviewer.stack.hu

Disclaimer: This code is just a proof of concept, do not use it in production environments without thorough testing.

-Jim

3 comments :

  1. Can we use POST,PUT Methods also in a similar fashion?

    ReplyDelete
    Replies
    1. Sadhna, this code is only used for converting json to property set. To use post and put method you will need to use EAI JSON Converter described here http://howtosiebel.blogspot.com/2013/12/eai-json-converter.html

      Delete
  2. Hi. When i save this code (parser) - i have error.

    Script compilation failed at line 5 in procedure 'jsonParser':
    Syntax error at Line 5 position 50:Expected '}'
    (SBL-SCR-00128).

    What is wrong? Thank you.

    ReplyDelete