<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>lekkimworld.comjson</title>
    <link>http://lekkimworld.com/tags/json/</link>
    <description>IBM Lotus Notes/Domino, Websphere, IBM Connections, mobile, web, JavaScript, Java...</description>
    <language>en</language>
    <copyright>Mikkel Flindt Heisterberg (mh [at] intravision [dot] dk</copyright>
    <pubDate>Sat, 19 May 2012 06:50:25 GMT</pubDate>
    <dc:creator>Mikkel Flindt Heisterberg (mh [at] intravision [dot] dk</dc:creator>
    <dc:date>2012-05-19T06:50:25Z</dc:date>
    <dc:language>en</dc:language>
    <dc:rights>Mikkel Flindt Heisterberg (mh [at] intravision [dot] dk</dc:rights>
    <image>
      <title>lekkimworld.comjson</title>
      <url>http://lekkimworld.com/tags/json/</url>
    </image>
    <item>
      <title>XPages JavaScript utility function of the day</title>
      <link>http://lekkimworld.com/2011/05/10/xpages_javascript_utility_function_of_the_day.html</link>
      <content:encoded>&lt;p&gt;
Yesterday and today I've been spending some time doing some XPages coding for a customer project and after spending quite some time doing Java plugin development I'm amazed of how easy XPages are. Don't get me wrong - there is still work to do for the XPages team but it's a joy to work with XPages and coding in JavaScript is just - well - flexible and fun.
&lt;/p&gt;
&lt;p&gt;
One of the real joys of JavaScript is it's dynamic nature and that it allows one to really cut down on the boilerplate and repeated code. For one I spent a lot of key pressed getting field values from backend documents in server side JavaScript. Instead of repeating the same ol' Document.getItemValueString(String) over and over again I did a neat little shortcut. Since I needed all items from a document I just created a utility function to JSONify a document to make it easier to access. The method is below.
&lt;/p&gt;
&lt;p&gt;
&lt;pre&gt;
var jsonifyDocument = function(doc) {
   var result = {};
   if (!doc) return result;
   var item;
   for (item in doc.getItems().toArray()) {
      result[item.getName().toLowerCase()] = item.getText();
   }
   return result;
};
&lt;/pre&gt;
So now instead of writing doc.getItemValueString all the time I can now just do property-like access to field values ("Heading" and "Description" are fields on the document). 
&lt;pre&gt;
var jsonDoc = jsonifyDocument(doc);
jsonDoc.heading + " (" + jsonDoc.description + ")";
&lt;/pre&gt;
&lt;/p&gt;
&lt;p&gt;
I also wrote a nice little Dojo-like mixin function to make my XAgents easy to configure. But that's for another day.
&lt;/p&gt;</content:encoded>
      <category domain="http://lekkimworld.com/tags/dojo/">dojo</category>
      <category domain="http://lekkimworld.com/tags/javascript/">javascript</category>
      <category domain="http://lekkimworld.com/tags/json/">json</category>
      <category domain="http://lekkimworld.com/tags/xagent/">xagent</category>
      <category domain="http://lekkimworld.com/tags/xpages/">xpages</category>
      <pubDate>Tue, 10 May 2011 12:05:02 GMT</pubDate>
      <guid isPermaLink="false">tag:lekkimworld.com,2011-05-10:default/1305029102437</guid>
      <dc:date>2011-05-10T12:05:02Z</dc:date>
    </item>
    <item>
      <title>Messing with JSON?</title>
      <link>http://lekkimworld.com/2008/07/17/messing_with_json.html</link>
      <content:encoded>&lt;p&gt;
Working with JSON can be a little tricky since it normally comes in as one long string which means it can be difficult to discover the data structure. I ran into this while pasing the search.twitter.com JSON API and needed a JSON viewer to help me out. A quick Google search later I found &lt;a href="http://www.codeplex.com/JsonViewer"&gt;JsonViewer&lt;/a&gt; which is a very nice small utility for perusing JSON data. No install necessary.
&lt;/p&gt;
&lt;p&gt;
If you're working with JSON check it out.
&lt;/p&gt;</content:encoded>
      <category domain="http://lekkimworld.com/tags/json/">json</category>
      <pubDate>Thu, 17 Jul 2008 05:02:00 GMT</pubDate>
      <guid isPermaLink="false">tag:lekkimworld.com,2008-07-17:default/1216270920000</guid>
      <dc:date>2008-07-17T05:02:00Z</dc:date>
    </item>
    <item>
      <title>JSONMap class</title>
      <link>http://lekkimworld.com/2007/02/19/jsonmap_class.html</link>
      <content:encoded>&lt;p&gt;
I'm starting off with converting some inhouse developed AJAX stuff to using &lt;a href="http://www.dojotoolkit.org"&gt;DOJO&lt;/a&gt; and for that reason I needed to convert my XML responses to JSON. Using the &lt;a href="http://www.json.org/java/index.html"&gt;JSON Java classes&lt;/a&gt; this was pretty straight forward but I really needed an easier way to convert a java.util.Map instance to JSON. Extending JSONArray this was easy. Provided here for those who might need similar code...
&lt;pre class="code"&gt;
package org.json;

import java.util.Iterator;
import java.util.Map;

public class JSONMap extends JSONArray {
   public JSONMap(Map m) {
      for (Iterator ite=m.keySet().iterator(); ite.hasNext(); ) {
         String key = (String)ite.next();
         String value = m.get(key).toString();
         JSONArray a = new JSONArray();
         a.put(value);
         a.put(key);
         this.put(a);
      }
   }
}
&lt;/pre&gt;
&lt;/p&gt;
&lt;p&gt;
Code like this
&lt;pre class="code"&gt;
Map m = new HashMap();
m.put("AL", "Alabama");
m.put("AK", "Alaska");
m.put("AR", "Arkansas");
JSONMap jm = new JSONMap(m);
System.out.println(jm.toString());
&lt;/pre&gt;
will output the following JSON
&lt;pre class="code"&gt;
[
    [ "Alabama", "AL" ],
    [ "Alaska", "AK" ],
    [ "Arkansas", "AR" ]
]
&lt;/pre&gt;
&lt;/p&gt;</content:encoded>
      <category domain="http://lekkimworld.com/categories/java/">Java</category>
      <category domain="http://lekkimworld.com/tags/dojo/">dojo</category>
      <category domain="http://lekkimworld.com/tags/java/">java</category>
      <category domain="http://lekkimworld.com/tags/json/">json</category>
      <pubDate>Mon, 19 Feb 2007 10:25:03 GMT</pubDate>
      <guid isPermaLink="false">tag:lekkimworld.com,2007-02-19:default/1171880703234</guid>
      <dc:date>2007-02-19T10:25:03Z</dc:date>
    </item>
  </channel>
</rss>


