@@ -89,7 +89,7 @@ private static YamlMappingNode ToYamlMapping(this JsonObject obj)
8989 {
9090 return new YamlMappingNode ( obj . ToDictionary ( x => ( YamlNode ) new YamlScalarNode ( x . Key )
9191 {
92- Style = double . TryParse ( x . Key , out _ ) ? ScalarStyle . DoubleQuoted : ScalarStyle . Plain
92+ Style = NeedsQuoting ( x . Key ) ? ScalarStyle . DoubleQuoted : ScalarStyle . Plain
9393 } , x => x . Value ! . ToYamlNode ( ) ) ) ;
9494 }
9595
@@ -135,6 +135,11 @@ ScalarStyle.Plain when YamlNullRepresentations.Contains(yaml.Value) => (JsonValu
135135 } ;
136136 }
137137
138+ private static bool NeedsQuoting ( string value ) =>
139+ decimal . TryParse ( value , NumberStyles . Float , CultureInfo . InvariantCulture , out _ ) ||
140+ bool . TryParse ( value , out _ ) ||
141+ YamlNullRepresentations . Contains ( value ) ;
142+
138143 private static YamlScalarNode ToYamlScalar ( this JsonValue val )
139144 {
140145 // Try to get the underlying value based on its actual type
@@ -145,9 +150,7 @@ private static YamlScalarNode ToYamlScalar(this JsonValue val)
145150 // For string values, we need to determine if they should be quoted in YAML
146151 // Strings that look like numbers, booleans, or null need to be quoted
147152 // to preserve their string type when round-tripping
148- var needsQuoting = decimal . TryParse ( stringValue , NumberStyles . Float , CultureInfo . InvariantCulture , out _ ) ||
149- bool . TryParse ( stringValue , out _ ) ||
150- YamlNullRepresentations . Contains ( stringValue ) ;
153+ var needsQuoting = NeedsQuoting ( stringValue ) ;
151154
152155 return new YamlScalarNode ( stringValue )
153156 {
0 commit comments