CSharp · Console
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
public class Program
{
public static void Main()
{
var obj1 = new A(4, true);
var obj2 = new B("hello world");
var json1 = JObject.FromObject(obj1);
var json2 = JObject.FromObject(obj2);
json1.Merge(json2);
Console.WriteLine(json1.ToString());
}
}
public class A
{
public A(int x, bool y)
{
X = x;
Y = y;
}
[JsonProperty("x_thing")]
public int X { get; }
[JsonProperty("y_thing")]
public bool Y { get; }
}
public class B
{
public B(string s)
{
S = s;
}
[JsonProperty("string_thing")]
public string S { get; }
}