Jarryd Jarryd - 6 months ago 57
C# Question

Why is the JSON save format changing between windows platforms

I have a struct, Vector2 that when serialized to JSON produces a different outpout on different platforms.

Struct I am serializing:

public struct Vector2 : IEquatable<Vector2>
public float X;

public float Y;


This struct is part of a class, that is part of a collection. This code is included on both platforms, and run on both platforms.

private static readonly JsonSerializerSettings JsonSerializerSettings = new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore };

public string ToJson()
return JsonConvert.SerializeObject(this, JsonSerializerSettings);

public static MenuEntryCollection FromJson(string in_Data)
return JsonConvert.DeserializeObject<MenuEntryCollection>(in_Data);

Result from UWP Serializer:

"SizeRelative": {
"X": 224.0,
"Y": 63.9999847

Result from Desktop Seralizer:

"SizeRelative": "384, 64",

Using Newtonsoft Json.net, 10.0.3

Why is the output different?
And why can one, not load the other?

Answer Source

JSON.NET uses an associated TypeConverter if that is available on the class/struct, this was originally only available in the .Net full framework.

For .Net core and UWP it will be added in the next release, as a part of .NET Standard 2.0, so if you are using Json.NET in both UWP and desktop, that is probably the issue.

Check for a TypeConverter on your class/struct. Removing it should make JSON.NET fall-back to the default serializer which is probably what you are getting on your UWP builds.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download