Simply add it to your Java agent, and then initialize it with a "JSONWriter.start()", passing "getAgentOutput()" as the sole parameter. This can be done from anywhere in your code, as long as it's before whenever you try to start printing JSON output. Just pass the string name of your JSON parameter, followed by either a string, variable, or boolean value. Close up the stream with "JSONWriter.end()" whenever you're finished.
(I have a git repo of this code at https://github.com/mdmadph/mdmjava.)
package util;
import java.io.PrintWriter;
import lotus.domino.NotesException;
/**
* @author mdm-adph
*
*/
public class JSONWriter {
/**
*
*/
private static PrintWriter printOutput = null;
/**
*
*/
private static boolean firstParam = true;
/**
* Default constrctor.
* @constructor
*/
private JSONWriter() throws NotesException {
}
/**
* Initializes the JSONWriter singleton with the desired PrintWriter
* @param pOutput {PrintWriter}
* The PrintWriter object to associate with JSONWriter,
* usually the result of getAgentOutput()
*/
public static synchronized void start(PrintWriter pOutput) {
if (printOutput == null) {
printOutput = pOutput;
printOutput.println("Content-type: application/json");
printOutput.println("{");
}
}
/**
* Internal function that prints the actual JSON information
* @param param {String}
* The string value of the JSON parameter name.
* @param value {String}
* The value of the JSON parameter.
*/
private static synchronized void printLine(String param, String value) {
if (firstParam) {
firstParam = false;
}
else {
printOutput.println(",");
}
printOutput.println("\"" + param + "\":" + value);
}
/**
* Public interface for printLine() for string params
* @param param {String}
* The string value of the JSON parameter name.
* @param value {String}
* The value of the JSON parameter.
*/
public static void print(String param, String value) {
printLine(param, "\"" + value + "\"");
}
/**
* Public interface for printLine for integer params
* @param param {String}
* The string value of the JSON parameter name.
* @param value {int}
* The value of the JSON parameter.
*/
public static void print(String param, int value) {
printLine(param, Integer.toString(value));
}
/**
* Public interface for printLine for Boolean params
* @param param {String}
* The string value of the JSON parameter name.
* @param value {Boolean}
* The value of the JSON parameter.
*/
public static void print(String param, Boolean value) {
printLine(param, Boolean.toString(value));
}
/**
* Closes the JSON stream
*/
public static synchronized void end() {
printOutput.println("}");
}
@Override
public Object clone() throws CloneNotSupportedException {
throw new CloneNotSupportedException(); // that'll teach 'em
}
}
![[image]](http://mowser.com/img?url=http%3A%2F%2F4.bp.blogspot.com%2F-GAqOpbbqqds%2FTgDdBrkhWRI%2FAAAAAAAABEc%2F1S7fNkkv918%2Fs320%2Fss-ie-addons-column-datetime.png)
![[image]](http://mowser.com/img?url=http%3A%2F%2F1.bp.blogspot.com%2F-iWlH0MQBtkQ%2FTa800G2njvI%2FAAAAAAAABDo%2FNqPUv4jtnkk%2Fs400%2FDominoWebAccessDirectTutorial_00.png)
![[image]](http://mowser.com/img?url=http%3A%2F%2F3.bp.blogspot.com%2F-jYXRabGIO0U%2FTa80091MxWI%2FAAAAAAAABDs%2FcSOogF0W8KU%2Fs320%2FDominoWebAccessDirectTutorial_01.png)
![[image]](http://mowser.com/img?url=http%3A%2F%2F4.bp.blogspot.com%2F-MF7z9xV97SM%2FTa84TmNN85I%2FAAAAAAAABD0%2Fm32IHEv3sCY%2Fs320%2FDominoWebAccessDirectTutorial_02.png)
![[image]](http://mowser.com/img?url=http%3A%2F%2F2.bp.blogspot.com%2F-cG-VcIAYZ84%2FTa84eVka7oI%2FAAAAAAAABD4%2FrBZh0Noiats%2Fs320%2FDominoWebAccessDirectTutorial_03.png)
![[image]](http://mowser.com/img?url=http%3A%2F%2F1.bp.blogspot.com%2F_w7Oc-a0bbsk%2FTQ-MXyFqsxI%2FAAAAAAAABAo%2FuTzvYd7DGV0%2Fs400%2Fblogger-mobile-web-template.jpg)



![[image]](http://mowser.com/img?url=http%3A%2F%2Fpics3.inxhost.com%2Fimages%2Fsticker.gif)
![[image]](http://mowser.com/img?url=http%3A%2F%2Fphotos1.blogger.com%2Fblogger%2F6885%2F3449%2F1600%2F80x15_3.png)

