Skip to content

ConvertTo-Json string escaped handling differs between PS and PSCore #7693

@PlagueHO

Description

@PlagueHO

Steps to reproduce

On PowerShell Core 6.0.4

ConvertTo-Json -InputObject @{ 'abc' = "'def'" }

Expected behavior

Windows PowerShell 5.x returns:

{
    "abc":  "\u0027def\u0027"
}

Actual behavior

PowerShell Core 6.0.4 returns:

{
  "abc": "'def'"
}

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      6.0.4
PSEdition                      Core
GitCommitId                    v6.0.4
OS                             Microsoft Windows 10.0.14393
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

This would appear to be because the StringEscapeHandling setting is set to Default in

JsonSerializerSettings jsonSettings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.None, MaxDepth = 1024 };

If the StringEscapeHandling setting is set to [Newtonsoft.Json.StringEscapeHandling]::EscapeHtml then the JSON string that is generated matches what is returned by Windows PowerShell.

image

Metadata

Metadata

Assignees

Labels

Committee-ReviewedPS-Committee has reviewed this and made a decisionIssue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-FixedThe issue is fixed.WG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility module

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions