Question

The following bit of code generates an error

W:\surge\ogre> @{SolutionDir='W:\Surge\ogre\'} | ConvertTo-Json
ConvertTo-Json : The converted JSON string is in bad format.
At line:1 char:35
+ @{SolutionDir='W:\Surge\ogre\'} | ConvertTo-Json
+                                   ~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Collections.Hashtable:PSObject) [ConvertTo-Json], InvalidOperationException
    + FullyQualifiedErrorId : JsonStringInBadFormat,Microsoft.PowerShell.Commands.ConvertToJsonCommand

Why? How could I fix this? This is in a prebuild event so I'm trying to keep it single-line and as compact as possible.

Was it helpful?

Solution

Using the -Compress switch should solve your problem. I believe this is a bug in PowerShell. Others have had similar problem with ex. values containing double quotes

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top