Skip to content

Instantly share code, notes, and snippets.

@iversond
Created March 29, 2017 17:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iversond/67ddae8529ecbc2b4e20f417ae0cdf36 to your computer and use it in GitHub Desktop.
Save iversond/67ddae8529ecbc2b4e20f417ae0cdf36 to your computer and use it in GitHub Desktop.
Process inbound JSON. Not very dynamic, but using some basic JSON types in PeopleCode to parse the message data.
method Process
/+ &_str as String +/
/+ Returns Boolean +/
/* Try using the JsonObject */
Local JsonParser &parser = CreateJsonParser();
Local boolean &status = &parser.Parse(&_str);
Local JsonObject &jo = &parser.GetRootObject();
Local JsonArray &jArray = &jo.GetJsonArray("Updates");
Local Record &m_email_stg = CreateRecord(Record.M_EMAIL_STG);
Local boolean &insResult;
Local boolean &result = True;
Local integer &j;
/* For each update array */
Local integer &childCount = &jArray.Length();
For &j = 1 To &childCount
Local JsonObject &arrElement = Null;
&arrElement = &jArray.GetJsonObject(&j);
If &arrElement.IsExist("EMPLID") Then
&m_email_stg.EMPLID.Value = &arrElement.GetString("EMPLID");
End-If;
If &arrElement.IsExist("EMAILID") Then
&m_email_stg.EMAILID.Value = &arrElement.GetString("EMAILID");
End-If;
If &arrElement.IsExist("USERIDALIAS") Then
&m_email_stg.USERIDALIAS.Value = &arrElement.GetString("USERIDALIAS");
End-If;
&insResult = &m_email_stg.Insert();
If &insResult = False Then
&result = False;
End-If
End-For;
Return &insResult;
end-method;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment