using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization.Formatters;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Collections.ObjectModel;
using System.Text.Json.Serialization;
using Newtonsoft.Json.Linq;
public static void Test()
String str = $"{{{System.Environment.NewLine}\t\"Name\": \"name_xxxx\",{System.Environment.NewLine}\t\"Version\": \"vesion_xxxx\",{System.Environment.NewLine}\t\"Platform\": \"platform_xxxx\",{System.Environment.NewLine}\t\"AgentUrl\": \"https://www.example.com\",{System.Environment.NewLine}\t\"Modules\":{{{System.Environment.NewLine}\t\t\"module1\":{{}},{System.Environment.NewLine}\t\t\"module2\":{{{System.Environment.NewLine}\t\t\t\"property1\": \"value1\",{System.Environment.NewLine}\t\t\t\"property2\": \"value2\"}}{System.Environment.NewLine}\t}},{System.Environment.NewLine}\t\"ModuleSources\":{{{System.Environment.NewLine}\t\t\t\"modulesource1\":{{{System.Environment.NewLine}\t\t\t\t\"url\": \"https://www.example.com\"}},{System.Environment.NewLine}\t\t\t\"modulesource2\":{{{System.Environment.NewLine}\t\t\t\t\"url\": \"https://www.example.com\"}}{System.Environment.NewLine}\t}},{System.Environment.NewLine}\t\"Environments\":[\"env1\", \"env2\"]{System.Environment.NewLine}}}";
JObject obj = JObject.Parse(str);
Console.WriteLine("Parsed {0}:", obj.GetType());
using var doc = JsonDocument.Parse(str);
Console.WriteLine("\nParsed {0}:", doc.RootElement.GetType());
Console.WriteLine(doc.RootElement);
Assert.IsTrue(JToken.DeepEquals(obj, JToken.Parse(doc.RootElement.ToString())));
public static void Main()
Console.WriteLine("Environment version: {0} ({1})", System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription , GetNetCoreVersion());
Console.WriteLine("System.Text.Json version: " + typeof(JsonSerializer).Assembly.FullName);
Console.WriteLine("Failed with unhandled exception: ");
public static string GetNetCoreVersion()
var assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly;
var assemblyPath = assembly.CodeBase.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
int netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App");
if (netCoreAppIndex > 0 && netCoreAppIndex < assemblyPath.Length - 2)
return assemblyPath[netCoreAppIndex + 1];