diff --git a/src/Automation/Automation/ChangeLog.md b/src/Automation/Automation/ChangeLog.md index df8af2c1803b..dd4893bc40b0 100644 --- a/src/Automation/Automation/ChangeLog.md +++ b/src/Automation/Automation/ChangeLog.md @@ -18,6 +18,7 @@ - Additional information about change #1 --> ## Upcoming Release +* Fixed the issue that string with escape chars cannot be converted into json object. ## Version 1.3.6 * Fixed typo in Example 1 in reference documentation for `New-AzAutomationSoftwareUpdateConfiguration` diff --git a/src/Automation/Automation/Common/PowershellJsonConverter.cs b/src/Automation/Automation/Common/PowershellJsonConverter.cs index 51a8c652eae2..2a3edc6c903c 100644 --- a/src/Automation/Automation/Common/PowershellJsonConverter.cs +++ b/src/Automation/Automation/Common/PowershellJsonConverter.cs @@ -19,6 +19,7 @@ using System.Globalization; using System.Management.Automation; using System.Text; +using Newtonsoft.Json; namespace Microsoft.Azure.Commands.Automation.Common { @@ -31,17 +32,7 @@ public static string Serialize(object inputObject) return null; } - Hashtable parameters = new Hashtable(); - parameters.Add(Constants.PsCommandParamInputObject, inputObject); - parameters.Add(Constants.PsCommandParamDepth, Constants.PsCommandValueDepth); - var result = PowerShellJsonConverter.InvokeScript(Constants.PsCommandConvertToJson, parameters); - - if (result.Count != 1) - { - return null; - } - - return result[0].ToString(); + return JsonConvert.SerializeObject(inputObject); } public static PSObject Deserialize(string json) @@ -51,16 +42,14 @@ public static PSObject Deserialize(string json) return null; } - Hashtable parameters = new Hashtable(); - parameters.Add(Constants.PsCommandParamInputObject, json); - var result = PowerShellJsonConverter.InvokeScript(Constants.PsCommandConvertFromJson, parameters); - if (result.Count != 1) + try { - return null; + object result = JsonConvert.DeserializeObject(json); + return new PSObject(result); + } catch + { + return json; } - - //count == 1. return the first psobject - return result[0]; } ///