So, I'm trying to build an app using Azure DocumentDb. DocumentDb stores data as json and the json-convention is to use camelCase. However the .net-convention is to use PascalCase. This just bit me in the ass when I tried to retrieve data from the db. I have made a data-export tool that operates on an old system. My models are all PascalCase, but I tell JsonConvert to convert to camelCase on serializing. Part of this is that the DocumentDb "id" column needs to be lowercase, and part is that I'm used to both conventions.
However, when I now want to use the models in my new app, none of the LINQ-queries work because json is case sensitive, so "Name" is not the same as "name".
So my question is really, would you prefer PascalCase in json (with exception for the "id" property) or would you use camelCase in the .net models. Or the third option, which sounds hideous. To use a [JsonProperty]-attribute on every field in the model that translates between camelCase and PascalCase?
Or have I missed something completely obvious?
I use json in my .net project and I use camelCase in my json and PascalCase in .net. Don´t see any problem why I should not use it like this.
Maybe you heard of, Newtonsoft Json is really awesome and is really helpful to convert a json document to a class model.
For those of you that vote for the facepalm, please elaborate ;)
Joe Clark
Full-stack developer specializing in healthcare IT
I wish I could say I was consistent. I'm not. I prefer camelCase, but there are days when it just looks... wrong. So then it's PascalCase. And there are days when that looks wrong. sigh
I'm a little surprised at the options, though. Most C# code I've seen uses PascalCode. Maybe the original devs were doing it wrong???