Will or should Sitecore automatically sanitize field names when serialising them as part of the layout service or do we need ensure we define fields in Sitecore using a consistent format?
e.g. would "Page Title" be serialised to pageTitle.
Will or should Sitecore automatically sanitize field names when serialising them as part of the layout service or do we need ensure we define fields in Sitecore using a consistent format?
e.g. would "Page Title" be serialised to pageTitle.
Layout service will not do anything with the field names when responding to any item request, you will be seeing field name in JSON response. It's basically our design to define an appropriate name(s) for fields. As per your ex- if you created a field with name "Page Title" then it will be returned as "Page Title".
Layout Service will only serialize field values and return appropriately. Each and every field type is having it's own serialization logic to return value in Layout service JSON.
For ex -
If you have "Single-Line-Text" field "pageTitle", value will be "pageTitle":{"value":"Welcome to Sitecore JSS"}
If you have an image field, value will be something similar to this, image":{"value":{"src":"https://example.com/-/media/img/apple-logo.ashx?h=550&w=800","alt":"","width":"800","height":"550"}}
You can see all serialization logics for all field types in this config \App_Config\Sitecore\LayoutService\Sitecore.LayoutService.config
<getFieldSerializer performanceCritical="true">
<processor type="Sitecore.LayoutService.Serialization.Pipelines.GetFieldSerializer.GetImageFieldSerializer, Sitecore.LayoutService" resolve="true">
<FieldTypes hint="list">
<fieldType id="1">image</fieldType>
</FieldTypes>
</processor>
......
</getFieldSerializer>