<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Development in a Blink &#187; JSON</title>
	<atom:link href="http://www.dougfinke.com/blog/index.php/category/json/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dougfinke.com/blog</link>
	<description>Researching the optimal; implementing the practical</description>
	<lastBuildDate>Sat, 08 Jun 2013 12:24:52 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>JSON is very nearly valid PowerShell</title>
		<link>http://www.dougfinke.com/blog/index.php/2012/09/16/json-is-very-nearly-valid-powershell/</link>
		<comments>http://www.dougfinke.com/blog/index.php/2012/09/16/json-is-very-nearly-valid-powershell/#comments</comments>
		<pubDate>Sun, 16 Sep 2012 22:12:30 +0000</pubDate>
		<dc:creator>Doug Finke</dc:creator>
				<category><![CDATA[JSON]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[PowerShell V3]]></category>

		<guid isPermaLink="false">http://www.dougfinke.com/blog/index.php/2012/09/16/json-is-very-nearly-valid-powershell/</guid>
		<description><![CDATA[JSON (JavaScript Serialized Object Notation) has become one of the standard formats for sending data by HTTP request between web browsers and other applications. Check out my other post Using PowerShell for dynamic JSON parsing. An example JSON string The basic types are objects, lists, strings, numbers, and nulls. All of the keys in an [...]]]></description>
				<content:encoded><![CDATA[<p><a href="http://json.org/">JSON</a> (JavaScript Serialized Object Notation) has become one of the standard formats for sending data by HTTP request between web browsers and other applications. Check out my other post <a href="http://www.dougfinke.com/blog/index.php/2012/09/03/using-powershell-for-dynamic-json-parsing/">Using PowerShell for dynamic JSON parsing</a>.</p>
<h3>An example JSON string</h3>
<p>The basic types are objects, lists, strings, numbers, and nulls. All of the keys in an object must be strings.</p>
<pre class="PowerShellColorizedScript"><span style="color: #ff4500">$json</span> <span style="color: #a9a9a9">=</span> <span style="color: #8b0000">@&quot;
{
 &quot;name&quot;: &quot;John&quot;,
 &quot;places_worked&quot;: [&quot;New York&quot;, &quot;Boston&quot;, &quot;California&quot;],
 &quot;pet&quot;: null,
 &quot;family&quot;: [{&quot;name&quot;: &quot;Eric&quot;, &quot;age&quot;: 43, &quot;pet&quot;: &quot;Rosco&quot;},
              {&quot;name&quot;: &quot;Dawn&quot;, &quot;age&quot;: 47, &quot;pet&quot;: &quot;Rocky&quot;}]
}
&quot;@</span></pre>
<h3>PowerShell v3 Supports JSON</h3>
<p>To convert a JSON string to a PowerShell object, use <em>ConvertFrom-JSON</em>. This PowerShell cmdlet is delivered out of the box with Version 3.</p>
<pre class="PowerShellColorizedScript" style="height: 131px; width: 539px"><span style="color: #ff4500">$json</span> <span style="color: #a9a9a9">|</span> <span style="color: #0000ff">ConvertFrom-Json</span>            
            
<span style="color: #8b0000">name places_worked                  pet family                                                            
---- -------------                  --- ------                                                            
John {New York, Boston, California}     {@{name=Eric; age=43; pet=Rosco}, @{name=Dawn; age=47; pet=Rocky}}</span></pre>
<p>Once converted, you can access individual properties of the PowerShell Object.</p>
<pre class="PowerShellColorizedScript"><span style="color: #000000">(</span><span style="color: #ff4500">$json</span> <span style="color: #a9a9a9">|</span> <span style="color: #0000ff">ConvertFrom-Json</span><span style="color: #000000">)</span><span style="color: #a9a9a9">.</span><span style="color: #000000">places_worked</span>            
            <span style="color: #8b0000">
New York
Boston
California</span></pre>
<h3>Manually Converting the JSON to PowerShell</h3>
<p>Starting with the original JSON example. I’ll remove it from the string and do several edits to make it valid PowerShell.</p>
<ol>
<li>Adding an <em><strong>@</strong></em> sign in from of the curly brackets makes it a hashtable </li>
<li>I cast the hashtable to a PowerShell object by using <em>[PSCustomObject]</em> </li>
<li>Replace the ‘:’ with ‘=’. Valid syntax for PowerShell hashtables </li>
<li>We’re building up a hashtable so, remove the ‘,’ or replace the with ‘;’</li>
<li>Change the ‘[]’ JSON array notation with ‘@()’ PowerShell array notation </li>
<li>Add a $ to null </li>
<li>Finally in the f<em>amily </em>property, I convert JSON Object notation to a PowerShell hashtable and cast it to an object with <em>[PSCustomObject]</em> </li>
</ol>
<p>&#160;</p>
<pre class="PowerShellColorizedScript" style="height: 154px; width: 548px"><span style="color: #ff4500">$list</span> <span style="color: #a9a9a9">=</span> <span style="color: #008080">[PSCustomObject]</span><span style="color: #000000">@{</span>            
 <span style="color: #8b0000">&quot;name&quot;</span> <span style="color: #a9a9a9">=</span> <span style="color: #8b0000">&quot;John&quot;</span>            
 <span style="color: #8b0000">&quot;places_worked&quot;</span> <span style="color: #a9a9a9">=</span> <span style="color: #000000">@(</span><span style="color: #8b0000">&quot;New York&quot;</span><span style="color: #a9a9a9">,</span> <span style="color: #8b0000">&quot;Boston&quot;</span><span style="color: #a9a9a9">,</span> <span style="color: #8b0000">&quot;California&quot;</span><span style="color: #000000">)</span>            
 <span style="color: #8b0000">&quot;pet&quot;</span> <span style="color: #a9a9a9">=</span> <span style="color: #ff4500">$null</span>            
 <span style="color: #8b0000">&quot;family&quot;</span> <span style="color: #a9a9a9">=</span> <span style="color: #000000">@(</span><span style="color: #008080">[PSCustomObject]</span><span style="color: #000000">@{</span><span style="color: #8b0000">&quot;name&quot;</span> <span style="color: #a9a9a9">=</span> <span style="color: #8b0000">&quot;Eric&quot;</span><span style="color: #000000">;</span> <span style="color: #8b0000">&quot;age&quot;</span> <span style="color: #a9a9a9">=</span> <span style="color: #800080">43</span><span style="color: #000000">;</span> <span style="color: #8b0000">&quot;pet&quot;</span><span style="color: #a9a9a9">=</span> <span style="color: #8b0000">&quot;Rosco&quot;</span><span style="color: #000000">}</span><span style="color: #a9a9a9">,</span>            
              <span style="color: #008080">[PSCustomObject]</span><span style="color: #000000">@{</span><span style="color: #8b0000">&quot;name&quot;</span> <span style="color: #a9a9a9">=</span> <span style="color: #8b0000">&quot;Dawn&quot;</span><span style="color: #000000">;</span> <span style="color: #8b0000">&quot;age&quot;</span> <span style="color: #a9a9a9">=</span> <span style="color: #800080">47</span><span style="color: #000000">;</span> <span style="color: #8b0000">&quot;pet&quot;</span> <span style="color: #a9a9a9">=</span> <span style="color: #8b0000">&quot;Rocky&quot;</span><span style="color: #000000">}</span><span style="color: #000000">)</span>            
<span style="color: #000000">}</span></pre>
<p>Now we can access individual properties just like before.</p>
<pre class="PowerShellColorizedScript"><p><span style="color: #ff4500">$list</span><span style="color: #a9a9a9">.</span><span style="color: #000000">family</span></p><p>
<span style="color: #8b0000"></span></p><p><span style="color: #8b0000">name age pet  
---- --- ---  
Eric  43 Rosco
Dawn  47 Rocky</span></p></pre>
<h3>Converting PowerShell Objects to JSON</h3>
<p>Often coming form PowerShell or .NET we want take our objects and convert them to JSON strings so we can store them or send them over HTTP. PowerShell excels at this on many levels. Lets take our newly created list and use the building <em>ConvertTo-JSON</em> cmdlet to get a JSON string.</p>
<pre class="PowerShellColorizedScript"><span style="color: #ff4500">$list</span> <span style="color: #a9a9a9">|</span> <span style="color: #0000ff">ConvertTo-Json</span>            
            
<span style="color: #8b0000">{
    &quot;name&quot;:  &quot;John&quot;,
    &quot;places_worked&quot;:  [
                          &quot;New York&quot;,
                          &quot;Boston&quot;,
                          &quot;California&quot;
                      ],
    &quot;pet&quot;:  null,
    &quot;family&quot;:  [
                   {
                       &quot;name&quot;:  &quot;Eric&quot;,
                       &quot;age&quot;:  43,
                       &quot;pet&quot;:  &quot;Rosco&quot;
                   },
                   {
                       &quot;name&quot;:  &quot;Dawn&quot;,
                       &quot;age&quot;:  47,
                       &quot;pet&quot;:  &quot;Rocky&quot;
                   }
               ]
}</span></pre>
<p>This string is ready to be sent over HTTP to an any endpoint that can handle JSON. See my other post <a href="http://www.dougfinke.com/blog/index.php/2012/09/03/using-powershell-for-dynamic-json-parsing/">Using PowerShell for dynamic JSON parsing</a>.</p>
<h3>Want more and Get 50% off?</h3>
<p>My new book <a href="http://goo.gl/eMn2q">“PowerShell for Developers”</a> covers these, other PowerShell v3 features and more. Use code <strong><font color="#ff0000">DSUG</font></strong> for the discount.</p>
<ul>
<li><a href="http://goo.gl/eMn2q"><img style="float: left; margin: 0px 34px 0px 0px; display: inline" align="left" src="http://www.dougfinke.com/blog/wp-content/uploads/2012/07/FrontCover.png" /></a>Slice and dice Text, XML, CSV, and JSON effortlessly </li>
<li>Embed PowerShell to provide scripting abilities for your C# apps </li>
<li>Create GUI applications five to ten times faster with less code </li>
<li>Leverage PowerShell’s capabilities to work with the Internet </li>
<li>Interact with DLLs and create objects, automatically display properties, and call methods in live interactive sessions </li>
<li>Build domain-specific languages (DSLs) and vocabularies to express solutions more clearly </li>
<li>Work with Microsoft Office via the Component Object Model (COM) </li>
<li>Discover PowerShell v3 features included with Windows 8 and Windows Server 2012 </li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.dougfinke.com/blog/index.php/2012/09/16/json-is-very-nearly-valid-powershell/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using PowerShell for dynamic JSON parsing</title>
		<link>http://www.dougfinke.com/blog/index.php/2012/09/03/using-powershell-for-dynamic-json-parsing/</link>
		<comments>http://www.dougfinke.com/blog/index.php/2012/09/03/using-powershell-for-dynamic-json-parsing/#comments</comments>
		<pubDate>Mon, 03 Sep 2012 13:37:19 +0000</pubDate>
		<dc:creator>Doug Finke</dc:creator>
				<category><![CDATA[JSON]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[PowerShell V3]]></category>

		<guid isPermaLink="false">http://www.dougfinke.com/blog/index.php/2012/09/03/using-powershell-for-dynamic-json-parsing/</guid>
		<description><![CDATA[With the release of PowerShell v3, working with JSON has become simple. After reading Rick Strahl’s post Using JSON.NET for dynamic JSON parsing I thought it’d be great to work up some of those examples in PowerShell. Check out what else you can do in PowerShell v3 here and here. Creating JSON on the fly [...]]]></description>
				<content:encoded><![CDATA[<p>With the release of PowerShell v3, working with JSON has become simple. After reading Rick Strahl’s post <a href="http://www.west-wind.com/weblog/posts/2012/Aug/30/Using-JSONNET-for-dynamic-JSON-parsing">Using JSON.NET for dynamic JSON parsing</a> I thought it’d be great to work up some of those examples in PowerShell.</p>
<p>Check out what else you can do in PowerShell v3 <a href="http://goo.gl/HDHqR">here</a> and <a href="http://goo.gl/QNlGX">here</a>.</p>
<h3>Creating JSON on the fly with ConvertTo-JSON</h3>
<p>Here is one simple way of creating JSON on the fly in PowerShell. I want to dial in on a couple of new PowerShell v3 features here. </p>
<p>First, I’m casting the hash table with <em>[ordered]</em> so the the keys will be in the order I add them.&#160; Casting&#160; to <em>[ordered] </em>creates an <em>OrderedDictionary</em> instead of <em>HashTable</em>.</p>
<p>Once I finish building up the ordered dictionary I pipe it to <em>ConvertTo-Json</em>, which, convers it to a JSON formatted string.</p>
<p>I need to set the depth to 3 with the <em>–Depth</em> parameter because the default is 2 levels of contained objects and my resulting structure has 3. The <em>$jsonObject</em>, <em>$album</em> and then <em>$songs</em>.</p>
<pre class="PowerShellColorizedScript"><span style="color: #ff4500">$jsonObject</span> <span style="color: #a9a9a9">=</span> <span style="color: #008080">[ordered]</span><span style="color: #000000">@{</span><span style="color: #000000">}</span>            
            
<span style="color: #ff4500">$jsonObject</span><span style="color: #a9a9a9">.</span><span style="color: #000000">Entered</span> <span style="color: #a9a9a9">=</span> <span style="color: #000000">(</span><span style="color: #0000ff">Get-Date</span><span style="color: #000000">)</span><span style="color: #a9a9a9">.</span><span style="color: #000000">DateTime</span>            
            
<span style="color: #ff4500">$album</span> <span style="color: #a9a9a9">=</span> <span style="color: #000000">@{</span><span style="color: #000000">}</span>            
<span style="color: #ff4500">$album</span><span style="color: #a9a9a9">.</span><span style="color: #000000">AlbumName</span> <span style="color: #a9a9a9">=</span> <span style="color: #8b0000">&quot;Dirty Deeds Done Dirt Cheap&quot;</span>            
<span style="color: #ff4500">$album</span><span style="color: #a9a9a9">.</span><span style="color: #000000">Artist</span> <span style="color: #a9a9a9">=</span> <span style="color: #8b0000">&quot;AC/DC&quot;</span>            
<span style="color: #ff4500">$album</span><span style="color: #a9a9a9">.</span><span style="color: #000000">YearReleased</span> <span style="color: #a9a9a9">=</span> <span style="color: #800080">1976</span>            
            
<span style="color: #ff4500">$album</span><span style="color: #a9a9a9">.</span><span style="color: #000000">Songs</span> <span style="color: #a9a9a9">=</span> <span style="color: #000000">@(</span><span style="color: #000000">)</span>            
                        
<span style="color: #ff4500">$song</span> <span style="color: #a9a9a9">=</span> <span style="color: #000000">@{</span><span style="color: #000000">}</span>            
<span style="color: #ff4500">$song</span><span style="color: #a9a9a9">.</span><span style="color: #000000">SongName</span> <span style="color: #a9a9a9">=</span> <span style="color: #8b0000">&quot;Dirty Deeds Done Dirt Cheap&quot;</span>            
<span style="color: #ff4500">$song</span><span style="color: #a9a9a9">.</span><span style="color: #000000">SongLength</span> <span style="color: #a9a9a9">=</span> <span style="color: #8b0000">&quot;4:11&quot;</span>            
<span style="color: #ff4500">$album</span><span style="color: #a9a9a9">.</span><span style="color: #000000">Songs</span> <span style="color: #a9a9a9">+=</span> <span style="color: #ff4500">$song</span>            
            
<span style="color: #ff4500">$song</span> <span style="color: #a9a9a9">=</span> <span style="color: #000000">@{</span><span style="color: #000000">}</span>            
<span style="color: #ff4500">$song</span><span style="color: #a9a9a9">.</span><span style="color: #000000">SongName</span> <span style="color: #a9a9a9">=</span> <span style="color: #8b0000">&quot;Love at First Feel&quot;</span>            
<span style="color: #ff4500">$song</span><span style="color: #a9a9a9">.</span><span style="color: #000000">SongLength</span> <span style="color: #a9a9a9">=</span> <span style="color: #8b0000">&quot;3:10&quot;</span>            
<span style="color: #ff4500">$album</span><span style="color: #a9a9a9">.</span><span style="color: #000000">Songs</span> <span style="color: #a9a9a9">+=</span> <span style="color: #ff4500">$song</span>            
            
<span style="color: #ff4500">$jsonObject</span><span style="color: #a9a9a9">.</span><span style="color: #000000">album</span> <span style="color: #a9a9a9">=</span> <span style="color: #ff4500">$album</span>            
            
<span style="color: #ff4500">$jsonObject</span> <span style="color: #a9a9a9">|</span> <span style="color: #0000ff">ConvertTo-Json</span> <span style="color: #000080">-Depth</span> <span style="color: #800080">3</span></pre>
<p>Here is the resulting JSON.</p>
<pre class="PowerShellColorizedScript"><span style="color: #8b0000">
{
&quot;Entered&quot;:  &quot;Saturday, September 01, 2012 10:30:04 AM&quot;,
&quot;album&quot;:  
    {
        &quot;Artist&quot;:  &quot;AC/DC&quot;,
        &quot;AlbumName&quot;:  &quot;Dirty Deeds Done Dirt Cheap&quot;,
        &quot;Songs&quot;:  [
                    {
                        &quot;SongName&quot;:  &quot;Dirty Deeds Done Dirt Cheap&quot;,
                        &quot;SongLength&quot;:  &quot;4:11&quot;
                    },
                    {
                        &quot;SongName&quot;:  &quot;Love at First Feel&quot;,
                        &quot;SongLength&quot;:  &quot;3:10&quot;
                    }
                ],
        &quot;YearReleased&quot;:  1976
    }
}</span></pre>
<h3>Creating a PowerShell Object from JSON with ConvertFrom-JSON</h3>
<p>Going the other way, this PowerShell snippet sets up a JSON string with three properties: <em>Name</em>, <em>Company</em> and <em>Entered</em>. Piping the string to <em>ConvertFrom-Json</em> creates a PowerShell object with these three properties.</p>
<pre class="PowerShellColorizedScript"><span style="color: #ff4500">$jsonString</span> <span style="color: #a9a9a9">=</span> <span style="color: #8b0000">@'
{
    &quot;Name&quot;:&quot;John&quot;,
    &quot;Company&quot;:&quot;Microsoft&quot;,
    &quot;Entered&quot;:&quot;2012-03-16T00:03:33.245-10:00&quot;
}
'@</span>            
            
<span style="color: #ff4500">$jsonString</span> <span style="color: #a9a9a9">|</span> <span style="color: #0000ff">ConvertFrom-Json</span></pre>
<p>The resulting PowerShell object displayed.</p>
<pre class="PowerShellColorizedScript"><span style="color: #8b0000">Name Company   Entered                      
---- -------   -------                      
John Microsoft 2012-03-16T00:03:33.245-10:00</span></pre>
<h3>Complex JSON</h3>
<p>Let’s take a look at a chewier JSON structure (<em>see below</em> the JSON string). From the string you can directly navigate to the objects, properties and elements of the arrays.</p>
<p><strong><em>Notice</em></strong> here I’m using the new PowerShell v3 <em>Member Enumeration </em>feature. That’s why the two dates, 1976 and 1992 are printed from the single line <em>$albums.YearReleased</em>.</p>
<pre class="PowerShellColorizedScript"><span style="color: #ff4500">$albums</span> <span style="color: #a9a9a9">=</span> <span style="color: #ff4500">$jsonString</span> <span style="color: #a9a9a9">|</span> <span style="color: #0000ff">ConvertFrom-Json</span>             
            
<span style="color: #ff4500">$albums</span><span style="color: #a9a9a9">.</span><span style="color: #000000">YearReleased</span>            
            
<span style="color: #ff4500">$albums</span><span style="color: #a9a9a9">[</span><span style="color: #800080">0</span><span style="color: #a9a9a9">]</span><span style="color: #a9a9a9">.</span><span style="color: #000000">AlbumName</span>            
<span style="color: #ff4500">$albums</span><span style="color: #a9a9a9">[</span><span style="color: #800080">0</span><span style="color: #a9a9a9">]</span><span style="color: #a9a9a9">.</span><span style="color: #000000">Songs</span><span style="color: #a9a9a9">[</span><span style="color: #800080">1</span><span style="color: #a9a9a9">]</span><span style="color: #a9a9a9">.</span><span style="color: #000000">SongName</span></pre>
<h3>Result navigating Complex JSON</h3>
<p>Here is what you get from running the previous script.</p>
<pre class="PowerShellColorizedScript"><span style="color: #8b0000">1976
1992
Dirty Deeds Done Dirt Cheap
Love at First Feel</span></pre>
<h3>JSON String</h3>
<p>This is the JSON string used in the previous example.</p>
<pre class="PowerShellColorizedScript"><span style="color: #ff4500">$jsonString</span> <span style="color: #a9a9a9">=</span> <span style="color: #8b0000">[
{
&quot;Id&quot;: &quot;b3ec4e5c&quot;,
&quot;AlbumName&quot;: &quot;Dirty Deeds Done Dirt Cheap&quot;,
&quot;Artist&quot;: &quot;AC/DC&quot;,
&quot;YearReleased&quot;: 1976,
&quot;Entered&quot;: &quot;2012-03-16T00:13:12.2810521-10:00&quot;,
&quot;AlbumImageUrl&quot;: &quot;http://ecx.images-amazon.com/images/I/61kTaH-uZBL._AA115_.jpg&quot;,
&quot;AmazonUrl&quot;: &quot;http://www.amazon.com/gp/product/…ASIN=B00008BXJ4&quot;,
&quot;Songs&quot;: [
    {
    &quot;AlbumId&quot;: &quot;b3ec4e5c&quot;,
    &quot;SongName&quot;: &quot;Dirty Deeds Done Dirt Cheap&quot;,
    &quot;SongLength&quot;: &quot;4:11&quot;
    },
    {
    &quot;AlbumId&quot;: &quot;b3ec4e5c&quot;,
    &quot;SongName&quot;: &quot;Love at First Feel&quot;,
    &quot;SongLength&quot;: &quot;3:10&quot;
    },
    {
    &quot;AlbumId&quot;: &quot;b3ec4e5c&quot;,
    &quot;SongName&quot;: &quot;Big Balls&quot;,
    &quot;SongLength&quot;: &quot;2:38&quot;
    }
]
},
{
&quot;Id&quot;: &quot;7b919432&quot;,
&quot;AlbumName&quot;: &quot;End of the Silence&quot;,
&quot;Artist&quot;: &quot;Henry Rollins Band&quot;,
&quot;YearReleased&quot;: 1992,
&quot;Entered&quot;: &quot;2012-03-16T00:13:12.2800521-10:00&quot;,
&quot;AlbumImageUrl&quot;: &quot;http://ecx.images-amazon.com/images/I/51FO3rb1tuL._SL160_AA160_.jpg&quot;,
&quot;AmazonUrl&quot;: &quot;http://www.amazon.com/End-Silence-Rollins-Band/dp/B0000040OX/ref=sr_1_5?ie=UTF8&amp;qid=1302232195&amp;sr=8-5&quot;,
&quot;Songs&quot;: [
    {
    &quot;AlbumId&quot;: &quot;7b919432&quot;,
    &quot;SongName&quot;: &quot;Low Self Opinion&quot;,
    &quot;SongLength&quot;: &quot;5:24&quot;
    },
    {
    &quot;AlbumId&quot;: &quot;7b919432&quot;,
    &quot;SongName&quot;: &quot;Grip&quot;,
    &quot;SongLength&quot;: &quot;4:51&quot;
    }
]
}]</span></pre>
<h3>Let’s Put some JSON on a Web endpoint</h3>
<p>Using <em>Invoke-RestMethod </em>you can send PowerShell objects that have been converted to JSON to a web endpoint. I’m using the freely hosted HTTP Request &amp; Response Service, <a title="http://httpbin.org" href="http://httpbin.org">http://httpbin.org</a>.</p>
<p>I get the first two processes from <em>Get-Process</em> and convert them to JSON.&#160; Then I add that JSON result to the overall payload and finally call <em>Invoke-RestMethod</em> which “puts” it to the web endpoint.</p>
<pre class="PowerShellColorizedScript"><span style="color: #ff4500">$p</span> <span style="color: #a9a9a9">=</span> <span style="color: #0000ff">Get-Process</span> <span style="color: #a9a9a9">|</span> <span style="color: #0000ff">Select</span> <span style="color: #000080">-First</span> <span style="color: #800080">2</span> <span style="color: #8a2be2">Name</span><span style="color: #a9a9a9">,</span> <span style="color: #8a2be2">Company</span><span style="color: #a9a9a9">,</span> <span style="color: #8a2be2">PM</span> <span style="color: #a9a9a9">|</span>             
        <span style="color: #0000ff">ConvertTo-Json</span>            
            
<span style="color: #ff4500">$jsonString</span> <span style="color: #a9a9a9">=</span> <span style="color: #8b0000">&quot;[{Date=$(Get-Date), Processes=$($p)}]&quot;</span>            
            
<span style="color: #ff4500">$body</span> <span style="color: #a9a9a9">=</span> <span style="color: #ff4500">$jsonString</span> <span style="color: #a9a9a9">|</span> <span style="color: #0000ff">ConvertTo-Json</span>            
            
<span style="color: #0000ff">Invoke-RestMethod</span> <span style="color: #000080">-Method</span> <span style="color: #8a2be2">Put</span> <span style="color: #8a2be2">http://httpbin.org/put</span> <span style="color: #000080">-Body</span> <span style="color: #ff4500">$body</span></pre>
<h3>Web Endpoint Results</h3>
<p>We can see from the <em>json</em> properties that the values were transmitted correctly.</p>
<pre class="PowerShellColorizedScript"><span style="color: #8b0000">origin  : 68.174.133.109
files   : 
form    : 
url     : http://httpbin.org/put
args    : 
headers : @{Content-Length=302; Host=httpbin.org; Content-Type=; Connection=keep-alive; User-Agent=Mozilla/5.0 (Windows NT; Windows NT 6.1; en-US) 
          WindowsPowerShell/3.0}
json    : [{Date=09/02/2012 15:23:26, Processes=[
              {
                  &quot;Name&quot;:  &quot;armsvc&quot;,
                  &quot;Company&quot;:  &quot;Adobe Systems Incorporated&quot;,
                  &quot;PM&quot;:  1249280
              },
              {
                  &quot;Name&quot;:  &quot;atieclxx&quot;,
                  &quot;Company&quot;:  &quot;AMD&quot;,
                  &quot;PM&quot;:  2473984
              }
          ]}]
data    : &quot;[{Date=09/02/2012 15:23:26, Processes=[\r\n    {\r\n        \&quot;Name\&quot;:  \&quot;armsvc\&quot;,\r\n        \&quot;Company\&quot;:  \&quot;Adobe Systems 
          Incorporated\&quot;,\r\n        \&quot;PM\&quot;:  1249280\r\n    },\r\n    {\r\n        \&quot;Name\&quot;:  \&quot;atieclxx\&quot;,\r\n        \&quot;Company\&quot;:  \&quot;AMD\&quot;,\r\n       
           \&quot;PM\&quot;:  2473984\r\n    }\r\n]}]&quot;</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dougfinke.com/blog/index.php/2012/09/03/using-powershell-for-dynamic-json-parsing/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Using PowerShell v3 to consume the StackOverflow JSON API</title>
		<link>http://www.dougfinke.com/blog/index.php/2012/02/08/using-powershell-v3-to-consume-stackoverflow-json-api/</link>
		<comments>http://www.dougfinke.com/blog/index.php/2012/02/08/using-powershell-v3-to-consume-stackoverflow-json-api/#comments</comments>
		<pubDate>Thu, 09 Feb 2012 00:40:21 +0000</pubDate>
		<dc:creator>Doug Finke</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[PowerShell V3]]></category>
		<category><![CDATA[StackOverflow]]></category>
		<category><![CDATA[Windows 7]]></category>
		<category><![CDATA[Windows 8]]></category>

		<guid isPermaLink="false">http://www.dougfinke.com/blog/index.php/2012/02/08/using-powershell-v3-to-consume-stackoverflow-json-api/</guid>
		<description><![CDATA[I was reading The Morning Brew and came across the entry below. I needed a break from writing my PowerShell Book, so I worked up the C# solution in PowerShell Using JSON.net to consume the JSON Stack Overflow API &#8211; Jonathan Creamer takes a look at consuming JSON powered APIs using .NET code, looking at [...]]]></description>
				<content:encoded><![CDATA[<p>I was reading <a href="http://blog.cwa.me.uk/2012/02/08/the-morning-brew-1039/">The Morning Brew</a> and came across the entry below. I needed a break from writing my PowerShell Book, so I worked up the C# solution in PowerShell</p>
<blockquote><p><a href="http://freshbrewedcode.com/jonathancreamer/2012/02/07/using-json-net-to-consume-the-json-stack-overflow-api/">Using JSON.net to consume the JSON Stack Overflow API</a> &#8211; Jonathan Creamer takes a look at consuming JSON powered APIs using .NET code, looking at the JSON.NET library as probably the best way of consuming such data, and exploring its use consuming the StackOverflow API.</p>
</blockquote>
<h3>PowerShell v3 Solution</h3>
<p>It’s worth comparing the number of lines it takes to get this done in C# vs. PowerShell. Put another way, <a href="http://www.dougfinke.com/blog/index.php/2011/11/09/design-patterns-in-dynamic-languagespowershell/">Ceremony vs. Essence</a>. Plus, this script is a one to one mapping to the C# done by Jonathan. I’m seamlessly integrating PowerShell with the .NET Framework. The only difference is I use the PowerShell Cmdlet <strong><em>ConvertFrom-Json</em></strong>. That does all the heavy lifting, converting the JSON to PowerShell objects with properties. No need to download a 3rd party DLL like JSON.net. Check out the results below.</p>
<pre class="PowerShellColorizedScript"><span style="color: #00008b">function</span> <span style="color: #8a2be2">Get-StackOverflowUser</span> <span style="color: #000000">(</span><span style="color: #ff4500">$id</span><span style="color: #a9a9a9">=</span><span style="color: #8b0000">&quot;110865&quot;</span><span style="color: #000000">)</span> <span style="color: #000000">{</span>            
               
    <span style="color: #ff4500">$url</span> <span style="color: #a9a9a9">=</span> <span style="color: #8b0000">&quot;http://api.stackoverflow.com/1.1/users/$id&quot;</span>            
    <span style="color: #ff4500">$data</span> <span style="color: #a9a9a9">=</span> <span style="color: #000000">(</span><span style="color: #0000ff">New-Object</span> <span style="color: #8a2be2">Net.WebClient</span><span style="color: #000000">)</span><span style="color: #a9a9a9">.</span><span style="color: #000000">DownloadData</span><span style="color: #000000">(</span><span style="color: #ff4500">$url</span><span style="color: #000000">)</span>            
    <span style="color: #ff4500">$memoryStream</span> <span style="color: #a9a9a9">=</span> <span style="color: #0000ff">New-Object</span> <span style="color: #8a2be2">System.IO.MemoryStream</span><span style="color: #000000">(</span><span style="color: #a9a9a9">,</span><span style="color: #ff4500">$data</span><span style="color: #000000">)</span>            
    <span style="color: #ff4500">$decompress</span> <span style="color: #a9a9a9">=</span> <span style="color: #0000ff">New-Object</span> <span style="color: #000000">`
</span>        <span style="color: #8a2be2">System.IO.Compression.GZipStream</span><span style="color: #000000">(</span><span style="color: #ff4500">$memoryStream</span><span style="color: #a9a9a9">,</span><span style="color: #8b0000">&quot;Decompress&quot;</span><span style="color: #000000">)</span>            
    <span style="color: #ff4500">$reader</span> <span style="color: #a9a9a9">=</span> <span style="color: #0000ff">New-Object</span> <span style="color: #8a2be2">System.IO.StreamReader</span><span style="color: #000000">(</span><span style="color: #ff4500">$decompress</span><span style="color: #000000">)</span>            
    <span style="color: #ff4500">$ret</span> <span style="color: #a9a9a9">=</span> <span style="color: #ff4500">$reader</span><span style="color: #a9a9a9">.</span><span style="color: #000000">ReadToEnd</span><span style="color: #000000">(</span><span style="color: #000000">)</span>            
            
    <span style="color: #000000">(</span><span style="color: #ff4500">$ret</span> <span style="color: #a9a9a9">|</span> <span style="color: #0000ff">ConvertFrom-Json</span><span style="color: #000000">)</span><span style="color: #a9a9a9">.</span><span style="color: #000000">Users</span>            
<span style="color: #000000">}</span>            
            
<span style="color: #0000ff">Get-StackOverflowUser</span> <span style="color: #800080">110865</span></pre>
<h3>Results</h3>
<pre class="PowerShellColorizedScript"><span style="color: #8b0000">user_id             : 110865
user_type           : registered
creation_date       : 1242960794
display_name        : Doug Finke
reputation          : 1666
email_hash          : 94c48c63e7e63f5e713f7f7a5cdbcac0
last_access_date    : 1328745843
website_url         : http://dougfinke.com/blog/
location            : New York, NY
about_me            : Software Developer and Microsoft PowerShell MVP
question_count      : 7
answer_count        : 72
view_count          : 70
up_vote_count       : 72
down_vote_count     : 2
accept_rate         : 71
user_questions_url  : /users/110865/questions
user_answers_url    : /users/110865/answers
user_favorites_url  : /users/110865/favorites
user_tags_url       : /users/110865/tags
user_badges_url     : /users/110865/badges
user_timeline_url   : /users/110865/timeline
user_mentioned_url  : /users/110865/mentioned
user_comments_url   : /users/110865/comments
user_reputation_url : /users/110865/reputation
badge_counts        : @{gold=0; silver=3; bronze=9}</span></pre>
<h3>Summary</h3>
<p>If you’re running Windows 7, you can download PowerShell v3 CTP2 <a href="http://www.microsoft.com/download/en/details.aspx?id=27548">HERE</a>. I hear the <a href="http://www.pcworld.com/article/249533/windows_8_consumer_preview_could_launch_feb_29.html">Windows 8 Consumer Preview could&#160; launch February 29</a>. Windows 8 comes with PowerShell v3 and both are pretty slick.</p>
<p>Well, back to writing another chapter in my PowerShell book, “Building GUIs in PowerShell”.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dougfinke.com/blog/index.php/2012/02/08/using-powershell-v3-to-consume-stackoverflow-json-api/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PowerShell &#8211; Using the New York Times Semantic Web APIs</title>
		<link>http://www.dougfinke.com/blog/index.php/2011/12/04/powershell-using-the-new-york-times-semantic-web-apis/</link>
		<comments>http://www.dougfinke.com/blog/index.php/2011/12/04/powershell-using-the-new-york-times-semantic-web-apis/#comments</comments>
		<pubDate>Sun, 04 Dec 2011 18:58:43 +0000</pubDate>
		<dc:creator>Doug Finke</dc:creator>
				<category><![CDATA[JSON]]></category>
		<category><![CDATA[New York Times]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[PowerShell V3]]></category>
		<category><![CDATA[Semantic Data]]></category>

		<guid isPermaLink="false">http://www.dougfinke.com/blog/index.php/2011/12/04/powershell-using-the-new-york-times-semantic-web-apis/</guid>
		<description><![CDATA[Mark Watson posted, Using the New York Times Semantic Web APIs. In it, he uses Clojure , AllegroGraph 4, Star Dog RDF repositories and his own NLP code. After requesting API Key from the New York Times, I worked up this reusable query in PowerShell. Time for more exploration. Note: This PowerShell code only works [...]]]></description>
				<content:encoded><![CDATA[<p>Mark Watson posted, <a href="http://blog.markwatson.com/2011/12/using-new-york-times-semantic-web-apis.html">Using the New York Times Semantic Web APIs</a>. In it, he uses Clojure , AllegroGraph 4, Star Dog RDF repositories and his own NLP code.</p>
<p>After requesting API Key from the New York Times, I worked up this reusable query in PowerShell. Time for more exploration.</p>
<p><strong>Note</strong>: This PowerShell code only works on <a href="http://www.microsoft.com/download/en/details.aspx?id=27548">Version 3</a>. I am using the new cmdlet <strong><em>Invoke-RestMethod</em></strong> and the simplified Where syntax.</p>
<pre class="PowerShellColorizedScript"><span style="color: #0000ff">Get-SemanticNYT</span> <span style="color: #8b0000">&quot;obama&quot;</span> <span style="color: #a9a9a9">|</span>            
    <span style="color: #0000ff">Get-SemanticNYTArticles</span> <span style="color: #a9a9a9">|</span>             
    <span style="color: #0000ff">where</span> <span style="color: #8a2be2">links</span> <span style="color: #a9a9a9">|</span>             
        <span style="color: #0000ff">select</span> <span style="color: #000080">-ExpandProperty</span> <span style="color: #8a2be2">article_list</span> <span style="color: #a9a9a9">|</span>             
        <span style="color: #0000ff">select</span> <span style="color: #000080">-ExpandProperty</span> <span style="color: #8a2be2">results</span> <span style="color: #a9a9a9">|</span>             
        <span style="color: #0000ff">select</span> <span style="color: #8a2be2">Title</span><span style="color: #a9a9a9">,</span> <span style="color: #8a2be2">Date</span><span style="color: #a9a9a9">,</span> <span style="color: #8a2be2">Body</span> <span style="color: #a9a9a9">|</span> <span style="color: #0000ff">Out-GridView</span></pre>
<h3>Injecting a GUI into the Command Line</h3>
<p>Out-GridView is one of the cmdlets delivered with PowerShell.</p>
<p><a href="http://www.dougfinke.com/blog/wp-content/uploads/2011/12/image4.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.dougfinke.com/blog/wp-content/uploads/2011/12/image_thumb4.png" width="614" height="197" /></a></p>
<h3>PowerShell Code</h3>
<p><span style="color: #000000">PowerShell’s parameter binding saves time and effort. Specifying <em>ValueFromPipelineByPropertyName</em>, lets me quickly pipe results from one Web API to the other. Letting PowerShell do the work of binding the output from one function to the other. This lets me focus on problem solving.</span></p>
<p><span style="color: #000000"><em><strong>Invoke-RestMethod </strong></em>does all the heavy lifting when interacting with the Web, <em>(Invoke-RestMethod $uri).results</em>:</span></p>
<ul>
<li><span style="color: #000000">Hits the endpoint</span></li>
<li><span style="color: #000000">Retrieves the JSON</span></li>
<li><span style="color: #000000">Converts the JSON to PowerShell objects</span><span style="color: #000000">&#160;</span></li>
</ul>
<pre style="width: 497px; height: 506px" class="PowerShellColorizedScript"><span style="color: #00008b">function</span> <span style="color: #8a2be2">Get-SemanticNYT</span> <span style="color: #000000">{</span>            
                
    <span style="color: #00008b">param</span><span style="color: #000000">(</span><span style="color: #ff4500">$query</span> <span style="color: #a9a9a9">=</span> <span style="color: #8b0000">&quot;obama&quot;</span><span style="color: #000000">)</span>            
            
    <span style="color: #ff4500">$uri</span> <span style="color: #a9a9a9">=</span> <span style="color: #8b0000">&quot;http://api.nytimes.com/svc/semantic/v2/&quot;</span><span style="color: #a9a9a9">+</span>            
        <span style="color: #8b0000">&quot;concept/search.json?query=$query&amp;api-key=$apiKey&quot;</span>            
            
    <span style="color: #000000">(</span><span style="color: #0000ff">Invoke-RestMethod</span> <span style="color: #ff4500">$uri</span><span style="color: #000000">)</span><span style="color: #a9a9a9">.</span><span style="color: #000000">results</span>            
<span style="color: #000000">}</span>            
            
<span style="color: #00008b">function</span> <span style="color: #8a2be2">Get-SemanticNYTArticles</span> <span style="color: #000000">{</span>            
                
    <span style="color: #00008b">param</span><span style="color: #000000">(</span>            
        <span style="color: #a9a9a9">[</span><span style="color: #00bfff">Parameter</span><span style="color: #000000">(</span><span style="color: #000000">ValueFromPipelineByPropertyName</span><span style="color: #000000">)</span><span style="color: #a9a9a9">]</span>            
        <span style="color: #ff4500">$concept_name</span><span style="color: #a9a9a9">,</span>            
        <span style="color: #a9a9a9">[</span><span style="color: #00bfff">Parameter</span><span style="color: #000000">(</span><span style="color: #000000">ValueFromPipelineByPropertyName</span><span style="color: #000000">)</span><span style="color: #a9a9a9">]</span>            
        <span style="color: #ff4500">$concept_type</span>            
    <span style="color: #000000">)</span>            
            
    <span style="color: #00008b">process</span> <span style="color: #000000">{</span>            
      <span style="color: #ff4500">$uri</span> <span style="color: #a9a9a9">=</span> <span style="color: #8b0000">&quot;http://api.nytimes.com/svc/semantic/v2/&quot;</span> <span style="color: #a9a9a9">+</span>            
      <span style="color: #8b0000">&quot;concept/name/$concept_type/$concept_name.json?&amp;&quot;</span> <span style="color: #a9a9a9">+</span>            
      <span style="color: #8b0000">&quot;fields=all&amp;api-key=$apiKey&quot;</span>            
            
      <span style="color: #000000">(</span><span style="color: #0000ff">Invoke-RestMethod</span> <span style="color: #ff4500">$uri</span><span style="color: #000000">)</span><span style="color: #a9a9a9">.</span><span style="color: #000000">results</span>            
    <span style="color: #000000">}</span>            
<span style="color: #000000">}</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dougfinke.com/blog/index.php/2011/12/04/powershell-using-the-new-york-times-semantic-web-apis/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Use PowerShell V3 to Find Out About Your Twitter Followers</title>
		<link>http://www.dougfinke.com/blog/index.php/2011/11/23/use-powershell-v3-to-find-out-about-your-twitter-followers/</link>
		<comments>http://www.dougfinke.com/blog/index.php/2011/11/23/use-powershell-v3-to-find-out-about-your-twitter-followers/#comments</comments>
		<pubDate>Thu, 24 Nov 2011 03:19:31 +0000</pubDate>
		<dc:creator>Doug Finke</dc:creator>
				<category><![CDATA[JSON]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[PowerShell V3]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.dougfinke.com/blog/index.php/2011/11/23/use-powershell-v3-to-find-out-about-your-twitter-followers/</guid>
		<description><![CDATA[Update Great feedback from the PowerShell community. I now use [Math]::Floor to avoid an error in rounding, if I use [int] it rounds up. Plus I de-pluralized the names of the functions. Thanks Chris and Aleksandar. This script lets you see your Twitter followers name, screen name and location. Using the new Invoke-RestMethod in PowerShell [...]]]></description>
				<content:encoded><![CDATA[<p><strong><font color="#ff0000">Update</font></strong></p>
<p><font color="#000000">Great feedback from the PowerShell community. I now use [Math]::Floor to avoid an error in rounding, if I use [int] it rounds up. Plus I de-pluralized the names of the functions. Thanks <a href="http://chrisjwarwick.wordpress.com/">Chris</a> and <a href="http://powershellers.blogspot.com/">Aleksandar</a>.</font></p>
<p>This script lets you see your Twitter followers name, screen name and location. Using the new <em>Invoke-RestMethod</em> in PowerShell Version 3, it retrieves and converts the JSON to make it easily accessible in PowerShell.</p>
<pre style="width: 320px; height: 24px" class="PowerShellColorizedScript"><span style="color: #0000ff">Get-TwitterFollower</span> <span style="color: #8a2be2">dfinke</span> <span style="color: #a9a9a9">|</span> <span style="color: #0000ff">Out-GridView</span></pre>
<p><a href="http://www.dougfinke.com/blog/wp-content/uploads/2011/11/image1.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.dougfinke.com/blog/wp-content/uploads/2011/11/image_thumb1.png" width="514" height="401" /></a></p>
<h3>The Code</h3>
<pre style="width: 592px; height: 414px" class="PowerShellColorizedScript"><span style="color: #00008b">function</span> <span style="color: #8a2be2">Get-TwitterFollower</span> <span style="color: #000000">(</span><span style="color: #ff4500">$screenName</span><span style="color: #000000">)</span> <span style="color: #000000">{</span>                        
            
    <span style="color: #ff4500">$baseUrl</span> <span style="color: #a9a9a9">=</span> <span style="color: #8b0000">&quot;https://api.twitter.com/1&quot;</span>            
    <span style="color: #00008b">function</span> <span style="color: #8a2be2">Get-Follower</span> <span style="color: #000000">(</span><span style="color: #ff4500">$userIds</span><span style="color: #000000">)</span> <span style="color: #000000">{</span>            
        <span style="color: #ff4500">$userIds</span> <span style="color: #a9a9a9">=</span> <span style="color: #000000">@(</span><span style="color: #ff4500">$userIds</span><span style="color: #000000">)</span> <span style="color: #a9a9a9">-join</span> <span style="color: #8b0000">&quot;,&quot;</span>            
        <span style="color: #ff4500">$url</span> <span style="color: #a9a9a9">=</span> <span style="color: #8b0000">&quot;$baseUrl/users/lookup.json?user_id=$($userIds)&amp;include_entities=true&quot;</span>            
        <span style="color: #000000">(</span><span style="color: #0000ff">Invoke-RestMethod</span> <span style="color: #ff4500">$url</span><span style="color: #000000">)</span> <span style="color: #a9a9a9">|</span>            
            <span style="color: #0000ff">select</span>  <span style="color: #8a2be2">name</span><span style="color: #a9a9a9">,</span> <span style="color: #8a2be2">screen_name</span><span style="color: #a9a9a9">,</span> <span style="color: #8a2be2">location</span>            
    <span style="color: #000000">}</span>                                    
            
    <span style="color: #ff4500">$url</span> <span style="color: #a9a9a9">=</span> <span style="color: #8b0000">&quot;$baseUrl/followers/ids.json?cursor=-1&amp;screen_name=$($screenName)&quot;</span>            
    <span style="color: #ff4500">$followers</span> <span style="color: #a9a9a9">=</span> <span style="color: #000000">(</span><span style="color: #0000ff">Invoke-RestMethod</span> <span style="color: #ff4500">$url</span><span style="color: #000000">)</span><span style="color: #a9a9a9">.</span><span style="color: #000000">ids</span>                                     
            
    <span style="color: #ff4500">$blocks</span>   <span style="color: #a9a9a9">=</span> <span style="color: #008080">[Math]</span><span style="color: #a9a9a9">::</span><span style="color: #000000">Floor</span><span style="color: #000000">(</span><span style="color: #ff4500">$followers</span><span style="color: #a9a9a9">.</span><span style="color: #000000">Count</span> <span style="color: #a9a9a9">/</span> <span style="color: #800080">100</span><span style="color: #000000">)</span>            
    <span style="color: #ff4500">$leftover</span> <span style="color: #a9a9a9">=</span> <span style="color: #ff4500">$followers</span><span style="color: #a9a9a9">.</span><span style="color: #000000">Count</span> <span style="color: #a9a9a9">%</span> <span style="color: #800080">100</span>                                    
            
    <span style="color: #00008b">for</span><span style="color: #000000">(</span><span style="color: #ff4500">$idx</span><span style="color: #a9a9a9">=</span><span style="color: #800080">0</span><span style="color: #000000">;</span> <span style="color: #ff4500">$idx</span> <span style="color: #a9a9a9">-lt</span> <span style="color: #ff4500">$blocks</span><span style="color: #000000">;</span> <span style="color: #ff4500">$idx</span><span style="color: #a9a9a9">+=</span><span style="color: #800080">1</span><span style="color: #000000">)</span> <span style="color: #000000">{</span>                    
        <span style="color: #0000ff">Get-Follower</span> <span style="color: #000000">(</span><span style="color: #ff4500">$followers</span> <span style="color: #a9a9a9">|</span> <span style="color: #0000ff">select</span> <span style="color: #000080">-First</span> <span style="color: #800080">100</span> <span style="color: #000080">-skip</span> <span style="color: #000000">(</span><span style="color: #ff4500">$idx</span><span style="color: #a9a9a9">*</span><span style="color: #800080">100</span><span style="color: #000000">)</span><span style="color: #000000">)</span>            
    <span style="color: #000000">}</span>            
                
    <span style="color: #0000ff">Get-Follower</span> <span style="color: #000000">(</span><span style="color: #ff4500">$followers</span> <span style="color: #a9a9a9">|</span> <span style="color: #0000ff">select</span> <span style="color: #000080">-First</span> <span style="color: #ff4500">$leftOver</span> <span style="color: #000080">-skip</span> <span style="color: #000000">(</span><span style="color: #ff4500">$idx</span><span style="color: #a9a9a9">*</span><span style="color: #800080">100</span><span style="color: #000000">)</span><span style="color: #000000">)</span>            
<span style="color: #000000">}</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dougfinke.com/blog/index.php/2011/11/23/use-powershell-v3-to-find-out-about-your-twitter-followers/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>PowerShell &#8211; Handling CSV and JSON</title>
		<link>http://www.dougfinke.com/blog/index.php/2011/10/22/powershell-handling-csv-and-json/</link>
		<comments>http://www.dougfinke.com/blog/index.php/2011/10/22/powershell-handling-csv-and-json/#comments</comments>
		<pubDate>Sat, 22 Oct 2011 14:36:02 +0000</pubDate>
		<dc:creator>Doug Finke</dc:creator>
				<category><![CDATA[JSON]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[PowerShell V3]]></category>
		<category><![CDATA[Windows 7]]></category>
		<category><![CDATA[Windows 8]]></category>

		<guid isPermaLink="false">http://www.dougfinke.com/blog/index.php/2011/10/22/powershell-handling-csv-and-json/</guid>
		<description><![CDATA[This will only work with PowerShell V3, which you can get by downloading the CTP for Windows 7 or downloading the Windows 8 Preview. This example takes a CSV string, converts it, using ConvertFrom-Csv,&#160; into PowerShell objects with the properties Name and Age and then converts it to JSON using ConvertTo-JSON. The csv data could [...]]]></description>
				<content:encoded><![CDATA[<p>This will only work with PowerShell V3, which you can get by downloading the <a href="http://www.microsoft.com/download/en/details.aspx?id=27548&amp;utm_source=feedburner&amp;utm_medium=twitter&amp;utm_campaign=Feed:+MicrosoftDownloadCenter+$Microsoft+Download+Center$">CTP for Windows 7</a> or downloading the <a href="http://msdn.microsoft.com/en-us/windows/home/">Windows 8 Preview</a>.</p>
<p>This example takes a CSV string, converts it, using <a href="http://technet.microsoft.com/en-us/library/dd315368.aspx">ConvertFrom-Csv</a><em></em>,&#160; into PowerShell objects with the properties Name and Age and then converts it to JSON using <em><a href="http://msdn.microsoft.com/en-us/library/hh485250(v=VS.85).aspx">ConvertTo-JSON</a></em>. The csv data could have been pulled from a file using <em><a href="http://technet.microsoft.com/en-us/library/dd347665.aspx">Import-CSV</a>.</em></p>
<p>The JSON can then be used in a post to a web service using PowerShell’s <a href="http://msdn.microsoft.com/en-us/library/hh485308(v=VS.85).aspx"><em>Invoke-RestMethod</em></a><em> –Method Post</em>.</p>
<pre style="width: 345px; height: 520px" class="PowerShellColorizedScript"><span style="color: #8b0000">@&quot;
Name, Age
John Doe, 10
Tom Doe, 20
Jane Doe, 30
Harry Doe, 40
&quot;@</span> <span style="color: #a9a9a9">|</span> <span style="color: #0000ff">ConvertFrom-Csv</span> <span style="color: #a9a9a9">|</span> <span style="color: #0000ff">ConvertTo-Json</span>            
            
            
<span style="color: #006400"># Results </span>            
<span style="color: #8b0000">@&quot;
{
    &quot;Name&quot;:  &quot;John Doe&quot;,
    &quot;Age&quot;:  &quot;10&quot;
}
{
    &quot;Name&quot;:  &quot;Tom Doe&quot;,
    &quot;Age&quot;:  &quot;20&quot;
}
{
    &quot;Name&quot;:  &quot;Dick Doe&quot;,
    &quot;Age&quot;:  &quot;30&quot;
}
{
    &quot;Name&quot;:  &quot;Harry Doe&quot;,
    &quot;Age&quot;:  &quot;40&quot;
}
&quot;@</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dougfinke.com/blog/index.php/2011/10/22/powershell-handling-csv-and-json/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell v3 and JSON</title>
		<link>http://www.dougfinke.com/blog/index.php/2011/09/15/powershell-v3-and-json/</link>
		<comments>http://www.dougfinke.com/blog/index.php/2011/09/15/powershell-v3-and-json/#comments</comments>
		<pubDate>Fri, 16 Sep 2011 00:45:50 +0000</pubDate>
		<dc:creator>Doug Finke</dc:creator>
				<category><![CDATA[CodePlex]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[PowerShell V3]]></category>
		<category><![CDATA[Windows 8 Server]]></category>
		<category><![CDATA[Wndows 8]]></category>

		<guid isPermaLink="false">http://www.dougfinke.com/blog/index.php/2011/09/15/powershell-v3-and-json/</guid>
		<description><![CDATA[Wow, it has been 4 years since I put Convert between PowerShell and JSON up on CodePlex. This week Microsoft released the Windows Developer Preview and PowerShell V3 was also delivered. Two of the new commands included, ConvertTo-JSON and ConvertFrom-JSON. I had fun building these scripts. From it I learned that PowerShell didn’t support Tail [...]]]></description>
				<content:encoded><![CDATA[<p>Wow, it has been 4 years since I put <a href="http://powershelljson.codeplex.com/">Convert between PowerShell and JSON</a> up on CodePlex. </p>
<p>This week Microsoft released the <a href="http://msdn.microsoft.com/en-us/windows/apps/br229516">Windows Developer Preview</a> and PowerShell V3 was also delivered. Two of the new commands included, ConvertTo-JSON and ConvertFrom-JSON.</p>
<p>I had fun building these scripts. From it I learned that PowerShell didn’t support <a href="http://c2.com/cgi/wiki?TailCallOptimization">Tail Call Optimization</a> and ended up using the <a href="http://en.wikipedia.org/wiki/Trampoline_(computing)">Trampoline Method</a>. Those were my early days working with PowerShell. We’ve both survived and come along way and are much stronger for it.</p>
<p>I’m looking forward to V3 being fully baked and released with Windows 8 and Windows 8 Server.</p>
<p>Here is my original post <a href="http://www.dougfinke.com/blog/index.php/2007/05/23/implementing-a-json-parser/">Implementing a JSON parser</a>.</p>
<p>These are the examples I put on the CodePlex page and the work verbatim with V3.</p>
<pre>PS C:\&gt; '[{&quot;title&quot;:&quot;PowerShell&quot;},{&quot;title&quot;:&quot;Test&quot;}]' | ConvertFrom-JSON

title
-----
PowerShell
Test</pre>
<pre>(New-Object PSObject |
   Add-Member -PassThru NoteProperty Name 'John Doe' |
   Add-Member -PassThru NoteProperty Age 10          |
   Add-Member -PassThru NoteProperty Amount 10.1     |
   Add-Member -PassThru NoteProperty MixedItems (1,2,3,&quot;a&quot;) |
   Add-Member -PassThru NoteProperty NumericItems (1,2,3) |
   Add-Member -PassThru NoteProperty StringItems (&quot;a&quot;,&quot;b&quot;,&quot;c&quot;)
) | ConvertTo-JSON</pre>
<pre>{
    &quot;Name&quot;:  &quot;John Doe&quot;,
    &quot;Age&quot;:  10,
    &quot;Amount&quot;:  10.1,
    &quot;MixedItems&quot;:  [
                       1,
                       2,
                       3,
                       &quot;a&quot;
                   ],
    &quot;NumericItems&quot;:  [
                         1,
                         2,
                         3
                     ],
    &quot;StringItems&quot;:  [
                        &quot;a&quot;,
                        &quot;b&quot;,
                        &quot;c&quot;
                    ]
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dougfinke.com/blog/index.php/2011/09/15/powershell-v3-and-json/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>One clear advantage of OData is its commonality</title>
		<link>http://www.dougfinke.com/blog/index.php/2011/06/02/one-clear-advantage-of-odata-is-its-commonality/</link>
		<comments>http://www.dougfinke.com/blog/index.php/2011/06/02/one-clear-advantage-of-odata-is-its-commonality/#comments</comments>
		<pubDate>Fri, 03 Jun 2011 02:01:06 +0000</pubDate>
		<dc:creator>Doug Finke</dc:creator>
				<category><![CDATA[AtomPub]]></category>
		<category><![CDATA[Cloud Computing]]></category>
		<category><![CDATA[Entity Data Model]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[OData]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[SOA]]></category>

		<guid isPermaLink="false">http://www.dougfinke.com/blog/index.php/2011/06/02/one-clear-advantage-of-odata-is-its-commonality/</guid>
		<description><![CDATA[If you care at all about how data is accessed&#8211;and you should&#8211;understanding the basics of OData is probably worth your time. Dave Chappell’s post, Introducing OData, does a great job walking through what OData is. Covering REST, Atom/AtomPub, JSON, OData filter query syntax, mobile devices, the Cloud and more. Our world is awash in data. [...]]]></description>
				<content:encoded><![CDATA[<blockquote><p>If you care at all about how data is accessed&#8211;and you should&#8211;understanding the basics of OData is probably worth your time.</p>
</blockquote>
<p>Dave Chappell’s post, <a href="http://davidchappellopinari.blogspot.com/2011/05/introducing-odata.html">Introducing OData</a>, does a great job walking through what OData is. Covering REST, Atom/AtomPub, JSON, OData filter query syntax, mobile devices, the Cloud and more.</p>
<blockquote><p>Our world is awash in data. Vast amounts exist today, and more is created every year. Yet data has value only if it can be used, and it can be used only if it can be accessed by applications and the people who use them.      <br />Allowing this kind of broad access to data is the goal of the <a href="http://www.odata.org/">Open Data Protocol</a>, commonly called just OData. <a href="http://davidchappellopinari.blogspot.com/2011/05/introducing-odata.html">This paper provides an introduction to OData</a>, describing what it is and how it can be applied.</p>
</blockquote>
<h3>OData PowerShell Explorer</h3>
<p>I open sourced an <a href="http://psodata.codeplex.com/">OData PowerShell Explorer</a> complete with a WPF GUI using <a href="http://archive.msdn.microsoft.com/PowerShellPack">WPK</a>. The PowerShell module allows you to discover and drill down through OData services using either the command line or the GUI interface.</p>
<h3>Other Resources</h3>
<ul>
<li><a href="http://odataprimer.com/">OData Primer</a> </li>
<li><a href="http://www.runasradio.com/default.aspx?showNum=173">RunAs Radio podcast on the OData PowerShell Explorer</a> </li>
<li><a href="http://www.odata.org/">Open Data Protocol</a> </li>
<li><a href="http://blogs.technet.com/b/heyscriptingguy/archive/2011/06/02/download-teched-sessions-automatically-by-using-powershell.aspx">Download TechEd Sessions Automatically by Using PowerShell</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.dougfinke.com/blog/index.php/2011/06/02/one-clear-advantage-of-odata-is-its-commonality/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Easily Convert PowerShell Objects to JSON</title>
		<link>http://www.dougfinke.com/blog/index.php/2009/08/12/easily-convert-powershell-objects-to-json/</link>
		<comments>http://www.dougfinke.com/blog/index.php/2009/08/12/easily-convert-powershell-objects-to-json/#comments</comments>
		<pubDate>Thu, 13 Aug 2009 00:48:03 +0000</pubDate>
		<dc:creator>Doug Finke</dc:creator>
				<category><![CDATA[CodePlex]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://dougfinke.com/blog/index.php/2009/08/12/easily-convert-powershell-objects-to-json/</guid>
		<description><![CDATA[I updated my CodePlex project Convert between PowerShell and JSON. I added ConvertTo-JSON which takes a PowerShell Object and generates a JSON string. Very handy. &#160;]]></description>
				<content:encoded><![CDATA[<p>I updated my CodePlex project <a href="http://powershelljson.codeplex.com/">Convert between PowerShell and JSON</a>. </p>
<p>I added ConvertTo-JSON which takes a PowerShell Object and generates a JSON string.</p>
<p>Very handy.</p>
<p><a href="http://powershelljson.codeplex.com/"><img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://dougfinke.com/uploadPictures/HowtoconvertPowerShellObjectstoJSON_1227E/image.png" width="576" height="303" />&#160;</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dougfinke.com/blog/index.php/2009/08/12/easily-convert-powershell-objects-to-json/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Chris Sells wants to learn PowerShell because of PowerBoots</title>
		<link>http://www.dougfinke.com/blog/index.php/2009/07/10/chris-sells-wants-to-learn-powershell-because-of-powerboots/</link>
		<comments>http://www.dougfinke.com/blog/index.php/2009/07/10/chris-sells-wants-to-learn-powershell-because-of-powerboots/#comments</comments>
		<pubDate>Sat, 11 Jul 2009 02:59:33 +0000</pubDate>
		<dc:creator>Doug Finke</dc:creator>
				<category><![CDATA[DSL]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[Oslo]]></category>
		<category><![CDATA[PowerBoots]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://dougfinke.com/blog/index.php/2009/07/10/chris-sells-wants-to-learn-powershell-because-of-powerboots/</guid>
		<description><![CDATA[Chris Sells, Program Manager on the Microsoft &#34;Oslo&#34; team, blogs&#160; how he has picked up and put down PowerShell a half dozen times. PowerBoots makes him really really want to move to PowerShell. PowerBoots makes it easy to create GUIs in PowerShell on top of WPF. Here are some posts on Boots and PowerShell JSON, [...]]]></description>
				<content:encoded><![CDATA[<p>Chris Sells, Program Manager on the Microsoft &quot;Oslo&quot; team, <a href="http://www.sellsbrothers.com/news/showTopic.aspx?ixTopic=2295">blogs</a>&#160; how he has picked up and put down PowerShell a half dozen times.</p>
<p><a href="http://huddledmasses.org/powerboots/">PowerBoots</a> makes him really really want to move to PowerShell. PowerBoots makes it easy to create GUIs in PowerShell on top of WPF.</p>
<p>Here are some posts on Boots and PowerShell</p>
<ul>
<li>
<h4><a href="http://dougfinke.com/blog/index.php/2009/07/03/json-xaml-powerboots-and-powershell/">JSON, XAML, PowerBoots and PowerShell</a></h4>
</li>
<li>
<h4><a href="http://dougfinke.com/blog/index.php/2009/07/01/powershell-powerboots-and-an-oslo-dsl-grammar/">PowerShell, PowerBoots and an Oslo DSL Grammar</a></h4>
</li>
<li>
<h4><a href="http://dougfinke.com/blog/index.php/2009/06/19/powershell-picture-viewer-using-wpf-with-powerboots/">PowerShell Picture Viewer using WPF with PowerBoots</a></h4>
</li>
<li>
<h4><a href="http://dougfinke.com/blog/index.php/2009/06/18/powershell-meet-wpf-via-powerboots/">PowerShell meet WPF via PowerBoots</a></h4>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.dougfinke.com/blog/index.php/2009/07/10/chris-sells-wants-to-learn-powershell-because-of-powerboots/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
