tag:blogger.com,1999:blog-34020393.post1287833910928958239..comments2024-03-27T10:59:38.307-07:00Comments on Jim's PeopleSoft Journal: JSON Encoding in PeopleCodeJim Marionhttp://www.blogger.com/profile/12995110203807924786noreply@blogger.comBlogger32125tag:blogger.com,1999:blog-34020393.post-26619223979038494272017-07-10T21:00:58.058-07:002017-07-10T21:00:58.058-07:00Thanks Jim for your suggestions. I will work on it...Thanks Jim for your suggestions. I will work on it and will update you accordingly.<br /><br />Appreciate your help!!Anonymoushttps://www.blogger.com/profile/04630014241092596201noreply@blogger.comtag:blogger.com,1999:blog-34020393.post-61740380176670641292017-07-10T14:19:05.319-07:002017-07-10T14:19:05.319-07:00Got it. You are expecting [\something] and you are...Got it. You are expecting [\something] and you aren't getting a regex containing that. Do you need to create &conv_regex as a JavaObject String? Can't you just use local string &conv_regex? The PeopleCode runtime should convert it to a Java string automatically. If not, then your way is fine. Also, is your regex supposed to have a '\' in it? If so, you might need '\\' in your PeopleCode.<br /><br />Without running the code, it is hard to know exactly why this is failing, but these are some of the things I would check.Jim Marionhttps://www.blogger.com/profile/12995110203807924786noreply@blogger.comtag:blogger.com,1999:blog-34020393.post-82092372351348686132017-07-10T14:07:03.387-07:002017-07-10T14:07:03.387-07:00I am having an issue with escape character at the ...<br />I am having an issue with escape character at the following piece of code. In 8.53.14 tools the same code is working fine but after upgrade to peopletools 8.55.13 it is not working king as expected and not conveying the .dat file into .Out file. Not getting any error. <br />Following is the piece of code which is causing an issue<br /><br /><br />For &idx = 1 To &parry_ConversionMatrix.Len<br /> <br />Local JavaObject &conv_regex = CreateJavaObject("java.lang.String", "[\" | &parry_ConversionMatrix [&idx][1] | "]");<br /><br />Anonymoushttps://www.blogger.com/profile/04630014241092596201noreply@blogger.comtag:blogger.com,1999:blog-34020393.post-18935705710034278792017-07-10T12:27:00.373-07:002017-07-10T12:27:00.373-07:00@grover, when you say, "Not working" wha...@grover, when you say, "Not working" what do you mean specifically? Is there an error? If so, what is the error?Jim Marionhttps://www.blogger.com/profile/12995110203807924786noreply@blogger.comtag:blogger.com,1999:blog-34020393.post-42255641193624016902017-07-10T12:20:04.883-07:002017-07-10T12:20:04.883-07:00Hi Jim this is my first post to the group and I am...Hi Jim this is my first post to the group and I am sure that I will get the solution to my problem. We recently upgraded our peoplesoft tools version to 8.55.13 where the following piece of code is not working hence need you expertise on this.<br />method doFileCharConversion<br />/+ &mFile_Name as String +/<br /> <br />Local File &lfile_ToConvert, &lfile_Converted;<br />Local number &lnbr_Pos;<br />Local string &lstr_ECOutName, &lstr_Data;<br /> <br />&lfile_ToConvert = GetFile(&mFile_Name, "r", "A", %FilePath_Absolute);<br /> <br />&lnbr_Pos = Find(".", &mFile_Name);<br />&lstr_ECOutName = Substring(&mFile_Name, 1, &lnbr_Pos) | "out";<br /> <br />&lfile_Converted = GetFile(&lstr_ECOutName, "W", "A", %FilePath_Absolute);<br />If &lfile_ToConvert.IsOpen And<br />&lfile_Converted.IsOpen Then<br /> <br />While &lfile_ToConvert.ReadLine(&lstr_Data);<br /> <br />For &idx = 1 To &parry_ConversionMatrix.Len<br /> <br />Local JavaObject &conv_regex = CreateJavaObject("java.lang.String", "[\" | &parry_ConversionMatrix [&idx][1] | "]");<br />Local JavaObject &test_string = CreateJavaObject("java.lang.String", &lstr_Data);<br /> <br />&lstr_Data = &test_string.replaceAll(&conv_regex, &parry_ConversionMatrix [&idx][2]);<br />End-For;<br /> <br />&lfile_Converted.WriteLine(&lstr_Data);<br />End-While;<br /> <br />&lfile_ToConvert.Delete();<br />&lfile_Converted.Close();<br />End-If;<br /> <br />end-method;<br />Anonymoushttps://www.blogger.com/profile/04630014241092596201noreply@blogger.comtag:blogger.com,1999:blog-34020393.post-46796158742699519392015-01-28T19:36:50.471-08:002015-01-28T19:36:50.471-08:00@Alex, I was referring to stateful/statelessness o...@Alex, I was referring to stateful/statelessness of the PeopleSoft session. It is possible to call a PeopleCode function from a PeopleCode function that halts the first PeopleCode and serializes the session (think-time functions). This serialization saves the state of ALL PeopleCode variables EXCEPT JavaObject variables. If you are experiencing this from an iScript, then I doubt you are having a think-time issue. iScripts run top to bottom with no stops... usually. I suspect there is something else causing your &json variable to be null. I would put some %Response.WriteLine(...) statements in the code to see if I can when it has a value, and when it doesn't. You can use the All() and None() functions to test if &json is valid. Hope that helps!Jim Marionhttps://www.blogger.com/profile/12995110203807924786noreply@blogger.comtag:blogger.com,1999:blog-34020393.post-76470054440549651042015-01-27T21:04:00.998-08:002015-01-27T21:04:00.998-08:00@Jim, great stuff. Keep em coming.
One thing, coul...@Jim, great stuff. Keep em coming.<br />One thing, could you elaborate on <br />"<br /> I protect against the "First operand of . is Null" error by lazily initializing the hashtable and the regular expression. A postback will reset the JavaObject to Null, and my lazy initialization code will reinitialize it.<br />", <br /><br />currently I'm getting that same error when using &json.getClass ().. after parsing json on the inbound from Iscript %Request.getparameter..<br /><br />Alex Shilmanhttps://www.blogger.com/profile/13008712556039336606noreply@blogger.comtag:blogger.com,1999:blog-34020393.post-89287668802116043502014-07-08T07:15:45.909-07:002014-07-08T07:15:45.909-07:00@Jim, I've included your code in the project, ...@Jim, I've included your code in the project, it fires anytime a string value is added to an object or an array.Cameron Barrehttps://www.blogger.com/profile/07058011185340144666noreply@blogger.comtag:blogger.com,1999:blog-34020393.post-66576291944008811452014-07-07T15:18:07.489-07:002014-07-07T15:18:07.489-07:00@Cameron, feel free to include the encoder shown i...@Cameron, feel free to include the encoder shown in this post. My post showed how to do the part you are missing, it didn't show how to convert an Array or object into a JSON structure like your code does.Jim Marionhttps://www.blogger.com/profile/12995110203807924786noreply@blogger.comtag:blogger.com,1999:blog-34020393.post-56964505471108192762014-07-07T13:08:28.685-07:002014-07-07T13:08:28.685-07:00I believe I've overlooked this, it's my fi...I believe I've overlooked this, it's my first library, thanks for taking the time to look through it. Looks like it still needs work!Cameron Barrehttps://www.blogger.com/profile/07058011185340144666noreply@blogger.comtag:blogger.com,1999:blog-34020393.post-90822598644056528432014-07-07T12:18:56.735-07:002014-07-07T12:18:56.735-07:00@Cameron, how are you escaping Strings to make the...@Cameron, how are you escaping Strings to make them JSON safe? I didn't see that in your source code.Jim Marionhttps://www.blogger.com/profile/12995110203807924786noreply@blogger.comtag:blogger.com,1999:blog-34020393.post-60704136259662007302014-07-07T10:55:46.688-07:002014-07-07T10:55:46.688-07:00Here is my getting started post:
http://cameronb...Here is my getting started post: <br /><br />http://cameronbarre.blogspot.com/2014/07/getting-up-and-running-with-jsoft.html <br /><br />There is also a link in the post to all of the method documentation. <br /><br />It's on Bitbucket here: https://bitbucket.org/cjbarre/jsoft.json<br /><br />I copied the project to file, I'm no expert, but I believe anyone with Peopletools 8.53.07 or higher will be able to import the project from file.<br /><br />I'm relatively new to the Peoplesoft scene, If anyone knows of a better way to package projects like this to make them easier to use, I'd appreciate the tips.Cameron Barrehttps://www.blogger.com/profile/07058011185340144666noreply@blogger.comtag:blogger.com,1999:blog-34020393.post-85312724573753259612014-07-07T09:57:53.813-07:002014-07-07T09:57:53.813-07:00@Cameron, yes, we are definitely interested. Can y...@Cameron, yes, we are definitely interested. Can you share a link to it? Did you blog about it or upload it to github or some other sharing location?Jim Marionhttps://www.blogger.com/profile/12995110203807924786noreply@blogger.comtag:blogger.com,1999:blog-34020393.post-65410800424958283782014-07-07T09:33:34.258-07:002014-07-07T09:33:34.258-07:00Hi, I've recently written a native JSON encode...Hi, I've recently written a native JSON encoder for Peoplecode, if anyone is interested.Cameron Barrehttps://www.blogger.com/profile/07058011185340144666noreply@blogger.comtag:blogger.com,1999:blog-34020393.post-327912045422811392013-09-23T22:44:10.547-07:002013-09-23T22:44:10.547-07:00@Stephen, that is a good question. Have you consid...@Stephen, that is a good question. Have you considered the "Is" functions, such as IsNumeric, IsDigits, etc? Other than those, you can also try using a try/catch block around an operation that requires numbers or strings. You can put that in a function. If it makes it through the operation, then set the return value to true.Jim Marionhttps://www.blogger.com/profile/12995110203807924786noreply@blogger.comtag:blogger.com,1999:blog-34020393.post-78810023769804691702013-09-23T22:13:35.999-07:002013-09-23T22:13:35.999-07:00Hi Jim, do you know of a way to determine the data...Hi Jim, do you know of a way to determine the data type of an "Any" variable? I'd like to be able to turn an Array of Any into a JSON array but to do that I have to be able to figure out the data type of each element. I've written a method to do this but it has some limitations, e.g. it can't distinguish between a number value in a Number variable and a number value in a String variable.Anonymoushttps://www.blogger.com/profile/17275212505247798366noreply@blogger.comtag:blogger.com,1999:blog-34020393.post-11534864485601322052013-09-11T22:20:20.776-07:002013-09-11T22:20:20.776-07:00@Stephen, thank you for sharing. I also created he...@Stephen, thank you for sharing. I also created helper methods to do things like encode rowsets, etc. Of note, PeopleTools 8.53's Documents module supports rendering and parsing JSON. What is interesting, though is that collections, etc, have to follow a specific pattern, so you can't just create any valid JSON structure you want. The reason I bring this up is because even though PT 8.53 supports JSON, I think we will still be using code like this to encode JSON.Jim Marionhttps://www.blogger.com/profile/12995110203807924786noreply@blogger.comtag:blogger.com,1999:blog-34020393.post-18759691456100154682013-09-11T21:39:07.039-07:002013-09-11T21:39:07.039-07:00Hi Jim, thank you for sharing your JSON encoding p...Hi Jim, thank you for sharing your JSON encoding peoplecode. I created an app package class using your code, then wrote extra methods to convert various types of data to JSON strings, for example...<br /><br />method BooleanToPair<br /> /+ &inLabel as String, +/<br /> /+ &inBoolean as Boolean +/<br /> /+ Returns String +/<br /> <br /> If None(&inLabel) Then<br /> Return "";<br /> Else<br /> Return %This.encodeLabel(&inLabel) | Lower(String(&inBoolean));<br /> End-If;<br /> <br />end-method;<br /><br />It makes it quite easy to create even reasonably complex JSON objects rather than coding them manually.<br /><br />Cheers,<br /><br />StephenAnonymoushttps://www.blogger.com/profile/17275212505247798366noreply@blogger.comtag:blogger.com,1999:blog-34020393.post-63497185610301118132013-05-20T09:15:35.365-07:002013-05-20T09:15:35.365-07:00@sarfaraz, I believe the missing piece in your cod...@sarfaraz, I believe the missing piece in your code is the XML wrapper for Integration Broker. Here is an example of code that I use to send non XML data (NOTE: I replaced less than/greater than with {} so blogger would accept this comment):<br /><br />Local string &nonXmlData = "{?xml version=""1.0""?}" |<br />"{data psnonxml=""yes""}{![CDATA[هذه هي اللغة العربية]]}{/data}";<br />Local XmlDoc &doc = CreateXmlDoc(&nonXmlData);<br /><br />If that doesn't work, the only other thing I can think of is encoding. Integration Broker is UTF-8. Just make sure your characters are within the allowed character range.Jim Marionhttps://www.blogger.com/profile/12995110203807924786noreply@blogger.comtag:blogger.com,1999:blog-34020393.post-25936712547123324942013-05-20T06:41:39.963-07:002013-05-20T06:41:39.963-07:00Hi Jim,
i want to show Arabic on my browser in web...Hi Jim,<br />i want to show Arabic on my browser in web service but Arabic words don't show. ?????? will show instead of Arabic.Here my code samle<br /><br />Local string &nonXmlData = "هذه هي اللغة العربية.";<br /> Local XmlDoc &DCM = CreateXmlDoc(&nonXmlData);<br /> Local string &outStr = &DCM.GenFormattedXmlString();<br /> <br /> <br /> <br /> <br /> &response = CreateMessage(Operation.LOGINSERVICE3_GET, %IntBroker_Response);<br /> &response.SetXmlDoc(&DCM); <br /><br />please suggest me how i encoded the Arabic in XMlDOC.. <br />Thanks in Advance<br />regards Sarfaraz Anonymoushttps://www.blogger.com/profile/10605084778731108515noreply@blogger.comtag:blogger.com,1999:blog-34020393.post-28666420906734845272013-04-29T18:35:37.269-07:002013-04-29T18:35:37.269-07:00@Ayesha, I wish I had something to offer you. It s...@Ayesha, I wish I had something to offer you. It sounds like an encoding issue (unicode, ascii, codepage, etc), but I think you already knew that. You may need to open a case with Oracle global support for this.Jim Marionhttps://www.blogger.com/profile/12995110203807924786noreply@blogger.comtag:blogger.com,1999:blog-34020393.post-91263699707640853022013-04-29T00:17:12.649-07:002013-04-29T00:17:12.649-07:00Hi Jim,
I have a problem regarding encoding data. ...Hi Jim,<br />I have a problem regarding encoding data. I have made my module in arabic and want to make web service but when i populate its JSON on page then its string pulated like "????????" plz guide me the solution?Anonymoushttps://www.blogger.com/profile/07401368328092930459noreply@blogger.comtag:blogger.com,1999:blog-34020393.post-87269822192398460262012-03-14T08:28:21.128-07:002012-03-14T08:28:21.128-07:00@Raj, I suspect the "garbled" issue has...@Raj, I suspect the "garbled" issue has to do with the string encoding (UTF, ASCII, etc). The easiest way to handle this type of character for HTML or XML is to use the HTML or XML entity rather than trust encodings. The HTML entity for this particular character is &eacute;. In XML you can use &#233; (the ascii character code for é). Therefore, to properly encode these types of characters, you can convert them to their ascii # and then sandwich them between &# and ;Jim Marionhttps://www.blogger.com/profile/12995110203807924786noreply@blogger.comtag:blogger.com,1999:blog-34020393.post-44882615951799082952012-03-14T00:39:32.331-07:002012-03-14T00:39:32.331-07:00Hi Jim,
I have a character encoding issue.I ma try...Hi Jim,<br />I have a character encoding issue.I ma trying to send a french character<br />é to a third party application.<br />However,the character is coming as garbled characters.Kindly suggest.<br /><br />Thanks in advance,<br />RajRajhttps://www.blogger.com/profile/16781608647948810858noreply@blogger.comtag:blogger.com,1999:blog-34020393.post-37740664976360544942011-04-27T07:55:09.554-07:002011-04-27T07:55:09.554-07:00@42N-71W,
Use an unstructured message and create ...@42N-71W,<br /><br />Use an unstructured message and create a single node XML document containing the attribute psnonxml="yes". Here is a PeopleCode snippet:<br /><br /><br />Local string &nonXmlData = "" |<br /> "";<br />Local XmlDoc &doc = CreateXmlDoc(&nonXmlData);<br /> <br />&response_msg.SetXmlDoc(&doc);<br />Return &response_msg;Jim Marionhttps://www.blogger.com/profile/12995110203807924786noreply@blogger.com