[Solved] How to order descending JSON content [closed]


Managed to get it working using JObject but it’s not pretty:

var json = "{\r\n\"Threads\": \r\n{\r\n    \"Program1\" : \r\n    {\r\n        \"Filepath\": \"C:\\\\ProgramFiles(x86)...\",\r\n        \"Priority\": 0\r\n    },\r\n    \"Program2\" : \r\n    {\r\n        \"Filepath\": \"C:\\\\ProgramFiles(x86)...\",\r\n        \"Priority\": 1\r\n    },\r\n    \"Program3\" : \r\n    {\r\n        \"Filepath\": \"C:\\\\ProgramFiles(x86)...\",\r\n        \"Priority\": 3\r\n    }\r\n}}";

var obj = JObject.Parse(json);

var threads = (JObject)obj["Threads"];

var sortedObj = new JObject(
    threads.Properties().OrderByDescending(p => (int)p.Value["Priority"])
);

Console.WriteLine(sortedObj.ToString(Formatting.Indented));

1

solved How to order descending JSON content [closed]