<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-1930213017396645687</id><updated>2012-03-20T02:03:49.525-06:00</updated><category term='facebook'/><category term='google maps'/><category term='truism'/><category term='defaction'/><category term='errorstack'/><category term='statcounter'/><category term='YQL'/><category term='firebug'/><category term='brightkite'/><category term='events'/><category term='linkedin'/><category term='edoism'/><category term='seo'/><category term='crud'/><category term='webhooks'/><category term='jquery'/><category term='iphone'/><category term='kynetx'/><category term='annotation'/><category term='css'/><category term='geolocation'/><category term='push'/><category term='aculis'/><category term='XPath'/><category term='twilio'/><category term='online identity'/><category term='twitter'/><category term='bigohoo'/><category term='oauth'/><category term='social media'/><category term='blogger template'/><category term='webapp'/><category term='JSON'/><category term='widget'/><category term='foursquare'/><category term='safari'/><title type='text'>edoism</title><subtitle type='html'>truism of ed orcutt</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://edoism.orcutt.org/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1930213017396645687/posts/default/-/JSON'/><link rel='alternate' type='text/html' href='http://edoism.orcutt.org/search/label/JSON'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Ed Orcutt</name><uri>http://www.blogger.com/profile/01072069799127687951</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_tXU2PrpKxHU/SuDD5YwomTI/AAAAAAAAAII/hCrRNUZWOto/S220/edo_transjpg.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>1</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1930213017396645687.post-4494211372236879170</id><published>2010-11-09T13:46:00.000-07:00</published><updated>2010-11-09T13:46:40.293-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JSON'/><category scheme='http://www.blogger.com/atom/ns#' term='kynetx'/><title type='text'>Happy Hack'in with Kynetx JSONPath</title><content type='html'>&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/_tXU2PrpKxHU/TNmv54DXY9I/AAAAAAAAAO0/ZGZ6f59Dxeo/s1600/JSON.gif" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/_tXU2PrpKxHU/TNmv54DXY9I/AAAAAAAAAO0/ZGZ6f59Dxeo/s1600/JSON.gif" /&gt;&lt;/a&gt;&lt;/div&gt;You can doing amazing things with the tools that are available to you, if you only take the time to learn how to use them. That was how I felt after taking the time to dig into the details of &lt;a href="http://docs.kynetx.com/docs/KRL_and_JSONPath"&gt;JSONPath&lt;/a&gt;. The Kynetx KRL language contains a number of mini languages, regex, jQuery, JSONPath, etc. While I was fortunate to have JSON data source for the &lt;a href="http://www.twilio.com/gallery/apps/CloudStatus"&gt;CloudStatus &lt;/a&gt;application, the structure of the data was not usable. Or so I initially thought.&lt;br /&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;br /&gt;First some background on the CloudStatus application. The CloudStatus application will provide a list of public API services that are having performance issues. Basically it will tell you which services are not ok. Fortunately I was able to find the JSON (actually JSONP) data which is used to build &lt;a href="http://api-status.com/"&gt;Public API Status&lt;/a&gt;. However, the JSON was structured so that it could be easily used to build a website which reports the status of all 26 services, not just report the bad ones. No problem I'll just write another utility application to transform the JSON into a structure that will be easier for the CloudStatus application to consume.&lt;br /&gt;&lt;br /&gt;Good idea, right? Well, yes, no, maybe. Honestly I really did not want to spend the time to code, test and debug an application that transformed JSON data. Sorry, it's just too tedious! But being lazy in this regard motivated me to dig into the details of what can be done with JSONPath. It's far more powerful that I initially assumed. And after about 30 minutes I was able to craft a JSONPath expression that extracted the data that I needed. Awesome!&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/_tXU2PrpKxHU/TNmthX1jzEI/AAAAAAAAAOw/_tznDWzS_rE/s1600/json.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/_tXU2PrpKxHU/TNmthX1jzEI/AAAAAAAAAOw/_tznDWzS_rE/s1600/json.png" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;The source JSON data was structured with the list of 26 services in random order. With 6 attributes provided for each of the services, including the name of the service and current status (ok, warn, or err). All that we need for the CloudStatus app is the list of services that are not ok. Using a JSONPath filter expression we grab a list of services where current status is not ok &lt;span style="font-family: inherit;"&gt;(current_status ne 'ok')&lt;/span&gt;. But since we only need the name of the services, not all of the attributes, we'll just retrieve the name:&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: javascript"&gt;BadServices = status_json.pick("$..services[?(@.current_status ne 'ok')].name")&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now &lt;i&gt;BadServices &lt;/i&gt;contains array of the services names that are having performance issues. And we didn't have to hack a pile of tedious code to transform the JSON into a new structure for our application to consume. Three cheers for JSONPath!&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: javascript"&gt;["bing search API", "Box.net API", "Flickr API"]&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;We still need to get the list into string format so that it can be passed to &lt;a href="http://www.twilio.com/"&gt;Twilio&lt;/a&gt;, and from an end user point of view we should remove the text "API". Using the KRL &lt;a href="http://docs.kynetx.com/docs/Join"&gt;join operator &lt;/a&gt;we can convert the array to a string:&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: javascript"&gt;BadString = BadServices.join(" and ")&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Giving us the the &lt;i&gt;BadString&lt;/i&gt;:&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: javascript"&gt;"bing search API and Box.net API and Flickr API"&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Finally, we remove all occurrences of the string "API" using the &lt;a href="http://docs.kynetx.com/docs/Replace"&gt;replace operator&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: javascript"&gt;YouAreBad = BadString.replace(re/ API/g, "")&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Which gives us a string containing the list of bad services:&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: javascript"&gt;"bing search and Box.net and Flickr"&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Enjoy and happy hack'in!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1930213017396645687-4494211372236879170?l=edoism.orcutt.org' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://edoism.orcutt.org/feeds/4494211372236879170/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://edoism.orcutt.org/2010/11/happy-hackin-with-kynetx-jsonpath.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1930213017396645687/posts/default/4494211372236879170'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1930213017396645687/posts/default/4494211372236879170'/><link rel='alternate' type='text/html' href='http://edoism.orcutt.org/2010/11/happy-hackin-with-kynetx-jsonpath.html' title='Happy Hack&apos;in with Kynetx JSONPath'/><author><name>Ed Orcutt</name><uri>http://www.blogger.com/profile/01072069799127687951</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://4.bp.blogspot.com/_tXU2PrpKxHU/SuDD5YwomTI/AAAAAAAAAII/hCrRNUZWOto/S220/edo_transjpg.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_tXU2PrpKxHU/TNmv54DXY9I/AAAAAAAAAO0/ZGZ6f59Dxeo/s72-c/JSON.gif' height='72' width='72'/><thr:total>0</thr:total></entry></feed>
