8 Aug 2012 by Emma Robinson

Parsing JSON in PowerShell, XML & The member "Item" is already present

I came across an annoying Powershell bug recently whilst working on a project to parse JSON data from the web in Powershell. I was working with the following script: Add-Type -Assembly System.ServiceModel.Web,System.Runtime.Serialization function Convert-JsonToXml([string]$json) { $bytes = [byte[]][char[]]$json $quotas = [System.Xml.XmlDictionaryReaderQuotas]::Max $jsonReader = [System.Runtime.Serialization.Json.JsonReaderWriterFactory]::CreateJsonReader($bytes,$quotas) try { $xml = new-object System.Xml.XmlDocument $xml.Load($jsonReader) $xml } finally { […]