Parsing JSON files with PowerShell on Azure VM’s using ConvertFrom-JSON

The Outdated Newtonsoft.JsonDLL Conspiracy

The Outdated Newtonsoft.Json.DLL Conspiracy

From our special agent Json Bourne: notes from the field.

Make sure you are reading a raw string: i.e. (Get-Content JsonFile.JSON -raw) | ConvertFrom-Json

PowerShell seems to use an outdated Newtonsoft.Json.DLL file which doesn’t fully support comments

Make sure there are no comments in the .JSON file – if there are any you may need to manually edit them out to get ConvertFrom-Json to behave

The two versions being used on Azure VM’s seem to be (October/2013) and (February/2014).

Support for comments in JSON files in Newtonsoft.Json.DLL was first added in version 5.03 from 2014/11 (support for single line comments) and expanded on in later versions (6.07+)

The latest version of Newtonsoft.Json.DLL is 10.0.2 (as of April/2017)


Newtonsoft.JSON on Github

If you put a comment into a Json file and try to run ConvertFrom-JSON in PowerShell on it you will get the following error message:

ConvertFrom-Json : Invalid object passed in, ‘:’ or ‘}’ expected. (1): {
At line:1 char:28
+ Get-Content .\config.JSON |ConvertFrom-Json -Verbose
+                            ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [ConvertFrom-Json], ArgumentException
+ FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.ConvertFromJsonCommand


An Introduction to JavaScript Object Notation (JSON) in JavaScript and .NET (February 2007)

Leave a Reply

Your email address will not be published.