Skip to content

Commit 9e82819

Browse files
Unquote primitive string values in JsonNode.ToString() (#117993)
1 parent dd7a848 commit 9e82819

File tree

3 files changed

+220
-218
lines changed

3 files changed

+220
-218
lines changed

src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonNode.To.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using System.Threading;
5-
64
namespace System.Text.Json.Nodes
75
{
86
public abstract partial class JsonNode
@@ -44,14 +42,14 @@ public override string ToString()
4442
// Special case for string; don't quote it.
4543
if (this is JsonValue)
4644
{
47-
if (this is JsonValuePrimitive<string> jsonString)
48-
{
49-
return jsonString.Value;
50-
}
51-
52-
if (this is JsonValueOfElement { Value.ValueKind: JsonValueKind.String } jsonElement)
45+
switch (this)
5346
{
54-
return jsonElement.Value.GetString()!;
47+
case JsonValuePrimitive<string> jsonString:
48+
return jsonString.Value;
49+
case JsonValueOfElement { Value.ValueKind: JsonValueKind.String } jsonElement:
50+
return jsonElement.Value.GetString()!;
51+
case JsonValueOfJsonString jsonValueOfJsonString:
52+
return jsonValueOfJsonString.GetValue<string>()!;
5553
}
5654
}
5755

0 commit comments

Comments
 (0)