Json.NET in Powershell

Apr 7, 2010 at 8:58 PM
Edited Apr 7, 2010 at 9:17 PM

I'm trying to use Powershell to access CouchDB.  I'm having a problem dealing with JSON arrays.  

My JSON input looks like this.

[
{"id":"amplify","key":"Amplify","value":"eurl1"},
{"id":"amplify","key":"Amplify","value":"url2"},
{"id":"ideas","key":"Ideas","value":"url3"},
{"id":"ideas","key":"Ideas","value":"url4"}
]

 

My Powershell looks like this.  I get an error that the collection is a fixed size.  I don't know what Powershell is doing with System.Collection.

$list = @()
[Newtonsoft.Json.JsonConvert]::PopulateObject($json, $list)
Exception calling "PopulateObject" with "2" argument(s): "Collection was of a fixed size."

 

This works for Populate object.

$list = New-Object collections.arraylist
[Newtonsoft.Json.JsonConvert]::PopulateObject($json, $list)

 

But causes a problem because there's an overlap of member "value.

format-default : The member "Value" is already present.

Can anyone offer any suggestions?  Thanks.