© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
1 reply
Arkobat

✅ Serializing a dictonary without path in root object

Hello, I'm trying to create a DTO for an API, where the request takes a dictornary of values, but the "keys" are part of the root object, and not under a path.
 {
   // Defined key value pairs
   "name": "Foo",
   "path": "Bar",
   
   // A map of language code to content
   "en": {},
   "de": {},
   "fr": {},
 }
 {
   // Defined key value pairs
   "name": "Foo",
   "path": "Bar",
   
   // A map of language code to content
   "en": {},
   "de": {},
   "fr": {},
 }


I'm therefor not sure how I can create a C# DTO, where the json output will like the example.
If I serilize the below, the language codes will be
languageMap.en
languageMap.en
etc, which does not match the request object
public class MyDto
{
    [JsonPropertyName("name")] public string Name { get; set; } = null!;
    [JsonPropertyName("path")] public string Path { get; set; } = null!;
    public Dictionary<string, object> LanguageMap { get; set; } = null!;
}
public class MyDto
{
    [JsonPropertyName("name")] public string Name { get; set; } = null!;
    [JsonPropertyName("path")] public string Path { get; set; } = null!;
    public Dictionary<string, object> LanguageMap { get; set; } = null!;
}


Is there a solution on how to serilize the dictionary into the root object, without ot being under the path?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Serializing related object EF
C#CC# / help
3y ago
Multi-Project templates without a root folder
C#CC# / help
3y ago
❔ Microsoft Graph SDK - Serializing objects
C#CC# / help
3y ago