Blog

Sitecore things

Sitecore best practices, architectures, EXM, SPEAK...

Keep Pascal Case for JSON Format in Your Sitecore Solution

More and more Sitecore solutions are adopting the architecture that exposes the content from back-end by using REST service. This can be achieved by using Sitecore.Services.Client or ASP.NET Web API to return JSON strings to the front-end.

The default JSON format returned from Sitecore.Services.Client or ASP.NET Web API are using Pascal Case like {"Id":1,"FirstName":"Yuqing"}. However, most front-end developers are feeling awkward to work with JavaScript objects where the first letter of a property name is a capital letter. So I saw some projects change that to Camel Case.

Unfortunately, this would introduce a serious problem in Sitecore after version 8. Sitecore 8 uses SPEAK as the front-end framework for most of its modules. And SPEAK consumes a lot of JSON strings returned from back-end.

Let’s check in List Manager for example.

The following is the default JSON string received in the front-end of List Manager. And it is using Pascal Case.

enter image description here

If your Sitecore solution introduces the Camel Case, then the JSON string would probably look like:

enter image description here

Since JavaScript is a case sensitive language, new camel case JSON string will cause a lot of SPEAK methods failed.

In short, keep using Pascal Case for JSON format in your solution.