By | 10 January 2017

JSON Parsing using PeopleCode Classes Starting in PeopleTools 8.55.11

I was listening to the the podcast and Kyle and Dan were talking about the newly released Elasticsearch support in PeopleTools 8.55.11. Dan Iverson mentioned that he found some PeopleCode that was interfacing with ElasticSearch that was generating and parsing JSON. This immediately peaked my interest. I have been struggling to work with JSON in PeopleSoft for a few years now and I have only been disappointed. I had written two previous articles about my work with JSON in PeopleCode:

I also submitted an Oracle Support "idea" that as of the time of writing had 70 up votes: JSON Support similar to XML PeopleCode Classes

I have struggled with the document technology myself and have completely abandoned its use. It would make sense that the "static structure" you must generate with the Document Technology would not work with Elasticsearch. From my limited work and reading on Elasticsearch, the only way to interact with the system is over a REST service that receives and sends JSON only. There is no XML, no SOAP, no real GUI to administer it by default.

So PeopleTools needs some way to dynamically generate and parse JSON when interfacing with the Elasticsearch. Thanks to Dan's comment I installed a DPK based on PeopleTools 8.55.11. Kyle and Dan were helpful again in this regard because they published a free Deployment Package Quick Start Course which gave me everything I needed to get a 8.55.11 instance running on AWS. This probably saved me hours of reading DPK documents. Since I am really a developer and not an PS Admin, I just needed the basics of getting a DPK running.

I went and found the Elasticsearch PeopleCode which lives in Application Package: PTSF_ES:*. Where I found references to two new PeopleCode classes: JsonBuilder and JsonObject. It looks like JsonBuilder is used for creating a JSON object. Here is a code snippet pulled out of some delivered code relating to Elasticsearch.

Local JsonBuilder &jbldr = CreateJsonBuilder();

If &jbldr.StartObjectReturnsTrue("") Then
    /* Specifications for Index creation */
    If &jbldr.StartObjectReturnsTrue("settings") Then
    If &jbldr.StartObjectReturnsTrue("index") Then
        &jbldr.AddProperty("number_of_shards", &nShards);
        &jbldr.AddProperty("number_of_replicas", &nReplicas);
    %This.AddIndexAnalysers(&jbldr, &saActiveLangs);

This would build JSON like this:

    "settings": {
        "index": {
            "number_of_shards": 1,
            "number_of_replicas": 2

The JsonObject is used for parsing a JSON String. Here is an example of Elasticsearch Ping method. In the code below you will see that:

  • a JsonObject is declared and instatiated into &response.
  • This code runs %This.doService(&m_url, "GET", Null); which will end up calling some Elasticsearch REST HTTP Service which will return JSON into &response.
  • Then the JsonObject.IsExist method is called to look for JSON object called version. If that exists then it pulls out the actual version number from the number JSON node.
  • There are further checks looking for error nodes in the JSON.
method Ping
   /+ Returns String +/
   /+ Extends/implements PT_SEARCH:SearchAdminService.Ping +/
   /* Ping returns the response to the getApiVersion op */
   Local string &ret = "";
   Local JsonObject &response = %This.doService(&m_url, "GET", Null);

   If &response.IsExist("version") Then
      Local JsonObject &version = &response.GetJsonObject("version");
      Local string &versionStr = &version.GetString("number");
      &ret = "Elasticsearch Version " | &versionStr;
   If &response.IsExist("error") Then
      If &response.GetNumber("status") = 401 Then
         Local string &errorStr = &response.GetString("error");
         throw CreateException(0, 0, &errorStr);
   If &ret = "" Then
      throw CreateException(0, 0, "Failed");
   Return &ret;

This is a very welcome change to PeopleTools. Having dynamic JSON parsing and creation built into PeopleTools is way past due. At the time of writing I found zero hits on Oracle support of PeopleBooks for JsonObject or JsonBuilder. I am sure that there will be some documeation at some point. Luckily you can use the code completion to peak at the methods and properties.

Here is what the JsonObject looks like.

Do you want to become a CI Expert?

If you want to learn more about developing using Component Interface then check out our CI Training Video.