title: Trying to get lotusscript json reader
body: <p>Through LotusScript I am consuming a webpage that returns json values and I have been unable to find any library out there for lotusscript, other than ls.snapps.JSONReader from openntf.  It works, but documentation is limited.  I am having trouble reading a nested array in the value list.  I was able to get it to work in java using the ibm.common.utils.... library, but was having trouble with mac client and another library (javax.swing.*) so I switched to LotusScript.</p>
  
  <p>I am hoping someone else has experience with the ls.snapps.JSONReader library, or maybe a different idea on how to do this.  Here is the sample:</p>
  
  <p>to read it I use</p>
  
  <pre><code>Dim jsonReader As jsonReader
  Dim vResults As Variant
  Dim vPieces As Variant
  Dim sJSON As string
  sJson= |{   "colorsArray":[{
              "red":"#f00",
              "green":"#0f0",
              "blue":"#00f",
              "cyan":"#0ff",
              "magenta":"#f0f",
              "yellow":"#ff0",
              "black":"#000"
          }
      ]
  }|
  
  Set jsonReader = New JsonReader
  Set vResults = jsonReader.parse(sJson)
  vPieces = vResults.items
  </code></pre>
  
  <p>I have no trouble when I set a single level object such as:</p>
  
  <pre><code>sJSON = |{"a":"a4255524","a24":true,"ax":"WER!!","b":"Some text"}|
  </code></pre>
  
  <p>I use the getItemValue method</p>
  
  <pre><code>msgbox vResults.getitemValue("a24")
  </code></pre>
  
  <p>will return a 'true' value</p>
  
  <p>Has anyone used this JSON parser and can you give me some advice on how to get the data out?</p>
  
  <hr>
  
  <p>UPDATE and interim solution:
  To get json values I had to do one of two things:</p>
  
  <ul>
  <li><p>use ls Replace functions to extract the single dimension data (ie, remove {"colorsArray":[  on the left side and ]}  on the right side., then use snapps json reader.</p></li>
  <li><p>I created a java library using the SBT JSON libs and called it from LotusScript.  Paul Bastide put a good writeup on using the java lib <a href="http://bastide.org/2014/03/15/using-the-ibm-social-business-toolkit-to-process-json-objects/" rel="nofollow">http://bastide.org/2014/03/15/using-the-ibm-social-business-toolkit-to-process-json-objects/</a></p></li>
  </ul>
  
  <p>Here is the java code:</p>
  
  <pre><code>import com.ibm.commons.util.io.json.JsonException;
  import com.ibm.commons.util.io.json.JsonJavaFactory;
  import com.ibm.commons.util.io.json.JsonJavaObject;
  import com.ibm.commons.util.io.json.JsonParser;
  import com.ibm.sbt.services.client.base.datahandlers.JsonDataHandler;
  import lotus.domino.*;
  public class GetJSON extends AgentBase  {
      public static String pJSON( String jData, String jEntry, String jValue ) {
          String result2="";
          try {
              System.out.println("data: " + jData + "\n" + "\n" + "jEntry &amp;     jValue: " + jEntry + ", " + jValue);
              // print to debug console
              // System.out.println("jData: " + jData);
              JsonJavaObject jsonObject = (JsonJavaObject) JsonParser.fromJson(JsonJavaFactory.instanceEx, jData );
              JsonDataHandler handler = new JsonDataHandler();
              handler.setData(jsonObject);
              JsonJavaObject entryJson=handler.getEntry(jEntry);
              result2=entryJson.getAsString(jValue);
      } catch (Exception e) {
              System.out.println("Error: " + e);
              e.printStackTrace();
              result2="";
          }
          return result2; }
  }
  </code></pre>
  
  <p>and I call it from LotusScript as follows:</p>
  
  <pre><code>Option Public
  Option Declare
  Use "($getJson)"
  UseLSX "*javacon"
  
  Dim mySession  As JavaSession
  Dim myClass As JavaClass
  Dim getJson As JavaObject
  result = ""
  '....
  'add vars here
  '....
  Set mySession = New JavaSession()
  Set myClass = mySession.GetClass("GetJSON")
  Set GetJson = myClass.CreateObject()
  
  
  MsgBox GetJson.pJSON( result2, "colorsArray", "red" )
  </code></pre>
  
  <p>IMPORTANT NOTE on the above, in the array string I had to remove the brackets [ and ] because I was getting an SBT array incompatibility error in java.  I think by doing that it may have turned it into a single level object, but if you look at Paul's example from above URL, you'll see he doesn't add them to his example either.</p>
  
  <p>I would rather do this in all Java or all LotusScript, and will probably use the modified json string with snapps, just looking for a better solution.</p>