How do I check two JSON objects are equal?

c#, json

Solution

Another way to compare json - Comparing JSON with JToken.DeepEquals

JObject o1 = new JObject
 {
    { "Integer", 12345 },
    { "String", "A string" },
    { "Items", new JArray(1, 2) }
 };

JObject o2 = new JObject
 {
    { "Integer", 12345 },
    { "String", "A string" },
    { "Items", new JArray(1, 2) }
 };

Console.WriteLine(JToken.DeepEquals(o1, o2));

Problem

I'm trying to discover if two JSON strings are equal. This is what I previously tried ``` var obj1 = Json.Decode("{\"ValueA\":1,\"ValueB\":2}") var obj2 = Json.Decode("{\"ValueB\":2,\"ValueA\":1}") // But then there seems to be no way to compare the two objects? ``` Surely there must exist an elegant simple way to what I thought would be a common task?

Original source

Related problems