Answered by:
JsonProperty to Pascal Case

Question
-
User-1256377279 posted
Hi All,
I am unable to convert camelCase property name to PascalCase
C#
public partial class RegionDataCSE { [JsonProperty("Nation")] public string Nation { get; set; } [JsonProperty("Region")] public string Region { get; set; } }
Json Result
[{"nation":"US","region":"South Carolina"}]
Expected Result
[{"Nation":"US","Region":"South Carolina"}]
Thanks,
Shabbir
Sunday, July 5, 2020 9:18 PM
Answers
-
User475983607 posted
Hi All,
I am unable to convert camelCase property name to PascalCase
C#
public partial class RegionDataCSE { [JsonProperty("Nation")] public string Nation { get; set; } [JsonProperty("Region")] public string Region { get; set; } }
Json Result
[{"nation":"US","region":"South Carolina"}]
Expected Result
[{"Nation":"US","Region":"South Carolina"}]
Please do not force the community to guess what you're doing. JsonProperty is a NewtonSoft (3rd party) attribute. You should take a few minutes to read the NewtonSoft docs. if you need help with basic configuration.
If you are using ASP.NET Core 3.X then the syntax is openly published on the official docs; https://docs.microsoft.com/en-us/dotnet/api/system.text.json.serialization.jsonpropertynameattribute?view=netcore-3.1
public partial class RegionDataCSE { [JsonPropertyName("Nation")] public string Nation { get; set; } [JsonPropertyName("Region")] public string Region { get; set; } }
[HttpGet] public RegionDataCSE Get() { RegionDataCSE model = new RegionDataCSE() { Nation = "Nation", Region = "Region" }; return model; }
Results
{ "Nation": "Nation", "Region": "Region" }
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Sunday, July 5, 2020 10:04 PM
All replies
-
User475983607 posted
Hi All,
I am unable to convert camelCase property name to PascalCase
C#
public partial class RegionDataCSE { [JsonProperty("Nation")] public string Nation { get; set; } [JsonProperty("Region")] public string Region { get; set; } }
Json Result
[{"nation":"US","region":"South Carolina"}]
Expected Result
[{"Nation":"US","Region":"South Carolina"}]
Please do not force the community to guess what you're doing. JsonProperty is a NewtonSoft (3rd party) attribute. You should take a few minutes to read the NewtonSoft docs. if you need help with basic configuration.
If you are using ASP.NET Core 3.X then the syntax is openly published on the official docs; https://docs.microsoft.com/en-us/dotnet/api/system.text.json.serialization.jsonpropertynameattribute?view=netcore-3.1
public partial class RegionDataCSE { [JsonPropertyName("Nation")] public string Nation { get; set; } [JsonPropertyName("Region")] public string Region { get; set; } }
[HttpGet] public RegionDataCSE Get() { RegionDataCSE model = new RegionDataCSE() { Nation = "Nation", Region = "Region" }; return model; }
Results
{ "Nation": "Nation", "Region": "Region" }
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Sunday, July 5, 2020 10:04 PM -
User-1256377279 posted
Thank u so much
Monday, July 6, 2020 7:18 AM