JSON

These coding standards clarify and standardise the format for JSON object, so that JSON files have a consistent look and feel. These guidelines are applicable for both content JSON in FE development and JSON files in AEM, also helpful for JSON requests and responses in both RPC-based and REST-based APIs.

Guidelines

  • No comments in JSON objects
  • Use double quotes
  • Allow one space between property name and property value
  • Use meaningful property names
  • Array types should have plural property names
  • Use camelCase for property names

Code Format

Only allow one space before the property value and no space before the colon:

{
	"propertyName": "propertyValue"
}

Array types usually have multiple items, using plural for the property name reflects this:

{
	"navigation": {
		"navigationLists": [
			{
				"label": "Home",
				"href": "#"
			},
			{
				"label": "Contact",
				"href": "#"
			}
		]
	}
}

There is no concept of namespacing in JSON. Versioning can be used to avoid naming conflicts:

{
	"apiVersion": "1.0",
	"data": {}
}

{
	"apiVersion": "2.0",
	"data": {}
}