Use anonymous class
Shape your model the way you want using anonymous classes:
var root = new
{
car = new
{
name = "Ford",
owner = "Henry"
}
};
string json = JsonConvert.SerializeObject(root);
More Related Contents:
- How to Convert JSON object to Custom C# object?
- Parse JSON in C#
- How to deserialize an array of values with a fixed schema to a strongly typed data class?
- Detect if deserialized object is missing a field with the JsonConvert class in Json.NET
- Casting interfaces for deserialization in JSON.NET
- “Self Referencing Loop Detected” exception with JSON.Net
- How to serialize/deserialize a custom collection with additional properties using Json.Net
- How to tell Json.Net globally to apply the StringEnumConverter to all enums
- Custom Deserialization using Json.NET
- How can I serialize/deserialize a dictionary with custom keys using Json.Net?
- What is the difference between PreserveReferencesHandling and ReferenceLoopHandling in Json.Net?
- JToken: Get raw/original JSON value
- How to call JsonConvert.DeserializeObject and disable a JsonConverter applied to a base type via [JsonConverter]?
- how to convert NameValueCollection to JSON string?
- Send JSON via POST in C# and Receive the JSON returned?
- Cannot deserialize JSON array into type – Json.NET
- How to apply indenting serialization only to some properties?
- JSON.net (de)serialize untyped property
- Ignoring null fields in Json.net
- Deserialize json object with dynamic items in C#
- Parsing a JSON array using Json.Net
- How can I merge two JObject? [duplicate]
- Json.NET adding backslash while returning json serialized string
- How do I get formatted and indented JSON in .NET using C#?
- Deserializing JSON into an object with Json.NET
- Json.net rename properties
- Newtonsoft JSON for .net is ignoring jsonproperty tags
- Is there a way in Json.NET serialization to distinguish between “null because not present” and “null because null”?
- dotnet core System.Text.Json unescape unicode string
- When using Trusted_Connection=true and SQL Server authentication, will this affect performance?