question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

uppercase/lowercase keys in the serialized JSON

See original GitHub issue

Given the class

public class MyClass {
    public string MyField {get;set;}
    public string MyOtherField {get;set;}
}

the generated JSON will be

{"MyField": "field value", "MyOtherField": "other field value"}

However, the REST API on the other end of the wire follows another naming convention where the keys are expected to be in lowercase, like

{"myField": "field value", "myOtherField": "other field value"}

Is there an easy way to achieve this without resorting to a custom serializer? It’s such a small change that preferrably it would only be a configuration switch somewhere.

Issue Analytics

  • State:closed
  • Created 11 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
pedrolamascommented, Mar 21, 2013

Use JsonPropertyattribute on the property to specify a different name when serialized!

public class MyClass {
    public string MyField {get;set;}
    [JsonProperty("myOtherField")]
    public string MyOtherField {get;set;}
}
0reactions
hallemcommented, May 20, 2015

it was not. if this feature is needed then RestSharp gives you the ability to use a custom de/serializer so you’d have to use that for now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ensuring json keys are lowercase in .NET
In Json.NET 9.0.1 and later it is possible to ensure that all property names are converted to lowercase by using a custom NamingStrategy...
Read more >
How to serialize properties to lower case using System. ...
How to serialize properties to lower case using System.Text.Json. ... lower case amount but Serialize method returns upper case Amount .
Read more >
SerializeJSON with lowercase keys and override ...
This legacy app basically provides JSON packets for a client side JS app. As such the client app is expecting all json keys...
Read more >
TIL: Dictionary keys are converted to lowercase too on ...
TIL: Dictionary keys are converted to lowercase too on serialization · 1. Configure Newtonsoft.Json NamingStrategy · 2. Use a comparer in your ...
Read more >
Convert JSON keys to lowercase? : r/learnpython
Where the first letter of a new word in a String for the key value is Capitalized. What I would like to do...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found