This forum is closed to new posts and responses. New discussions are now taking place in the IBM Developer Answers forum.

May 17, 2017, 3:51 AM
9 Posts

Java agent - convert JSON to Notes documents

  • Category: Domino Designer
  • Platform: All Platforms
  • Release: 9.0.1
  • Role: Developer
  • Tags: agent,java,json
  • Replies: 2

I need to read mesasges from Websphere MQ that are in JSON format. The JSON should be converted to Notes documents. Does anyone has any guidelines / instructions which I can use?

May 17, 2017, 8:21 AM
362 Posts
And how do they map?

When you get to developing some scripts for importing, there are decisions you need to make.

Any objects within the main JSON object would need to be mapped to something: Notes documents contain individual fields with no subfields, excepting (up to 64k of) multiple values for a field.

What'd you like to do with the JSON?

Clearly the JSON could be pushed directly into a richtext object if you want that.

May 17, 2017, 3:06 PM
82 Posts
Here's a sample to get you started ...
import lotus.domino.*;
import org.json.JSONObject;
import org.json.JSONException;

import java.util.*;

public class JavaAgent extends AgentBase {
        JSONObject MESSAGE_SELECTION = null;
        String jsonName="";
        public void NotesMain() {
                try {
                        Session session = getSession();
                        AgentContext agentContext = session.getAgentContext();
                        Document doc = agentContext.getDocumentContext();  //incoming mail message
                        //Document doc = agentContext.getUnprocessedDocuments().getFirstDocument();  //used for debug
                        if (doc.getItemValueString("Subject").equals("")){
                                doc.replaceItemValue("Subject", "**NO DEFECT TITLE**");
                        doc.replaceItemValue("Form", "Defect");
                        doc.replaceItemValue("Status",        "Needs Triage");
                        Vector defectID = session.evaluate("@Unique");
                        doc.replaceItemValue("DefectID",defectID.toString().replaceAll("[^A-Za-z0-9 ]", ""));
                        Item readbody = doc.getFirstItem("Body");
                        String bodyText = scrubText(readbody.getText().replaceAll("[\n]",""));
                        String jsonText = "";
                        int  defInfoPosStart, defInfoPosEnd ;
                        defInfoPosStart = bodyText.indexOf ("DefectInfoStart") + 15 ;
                        defInfoPosEnd = bodyText.indexOf ("DefectInfoEnd");        
                        jsonText = bodyText.substring (defInfoPosStart, defInfoPosEnd) ;

                                MESSAGE_SELECTION = new JSONObject(jsonText);
                                Iterator props = MESSAGE_SELECTION.keys();
                                while (props.hasNext()){
                                        jsonName = (String);
                                        doc.replaceItemValue(jsonName, MESSAGE_SELECTION.getString(jsonName));
                        }catch(JSONException Je){

                } catch(Exception e) {

         * remove all ascii 13 char from the json string that will be passed to JSONObject constructor
        public String scrubText(String jsonText){
                String returnText="";
                for (int count=0; count < jsonText.length(); count++)
                        if ((int)jsonText.charAt(count)!=13){
                                returnText += jsonText.charAt(count);
                return returnText;

         * Strip all unnecessary items from the Note
        public void removeItems(Document mailDoc){
                String[] keeperItems = {"From","INetFrom","Body","Subject","$FILE"};
                        Vector items = mailDoc.getItems();
                        for (int i=0; i<items.size(); i++) {
                                Item item = (Item)items.elementAt(i);
                                if (Arrays.asList(keeperItems).indexOf(item.getName())<0){
                } catch(Exception e) {
        public String encodeURL(String url) {
                try {
                        return URLEncoder.encode(url, "UTF-8");
                } catch (UnsupportedEncodingException e) {
                        return url;


This forum is closed to new posts and responses. New discussions are now taking place in the IBM Developer Answers forum.