Hi,
We use JsonObject on our API for a scenario where the type (of a single property) is dynamic and we just ran into an issue with escaped backslashes being doubled. It looks like not all code agrees if the internal values in the JsonObject dictionary are escaped or not.
I think the code below demonstrates the problem pretty clearly. Parsing some json with escapes into a JsonObject and then serializing it again results in double escaping:
using System.Diagnostics;
using ServiceStack;
using ServiceStack.Text;
var a = new Thing()
{
Name = "With\\Backslash",
Val = "With\"Escaped",
};
var json = a.ToJson();
Console.WriteLine(json); // Correctly escaped.
JsonObject jsonObject = JsonObject.Parse(json);
Console.WriteLine(jsonObject.SerializeToString()); // Escaping doubled
Console.WriteLine(jsonObject.ToJson()); // Escaping doubled
var b = jsonObject.ConvertTo<Thing>(); // Works as expected
Debug.Assert(a.Name == b.Name);
class Thing
{
public string Name { get; set; }
public string Val { get; set; }
}
Am I missing something here, or is this a bug in JsonObject?