Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Automation/Automation/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
27 changes: 8 additions & 19 deletions src/Automation/Automation/Common/PowershellJsonConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using System.Globalization;
using System.Management.Automation;
using System.Text;
using Newtonsoft.Json;

namespace Microsoft.Azure.Commands.Automation.Common
{
Expand All @@ -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)
Expand All @@ -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];
}

/// <summary>
Expand Down