We´re developing a JSON API to deliver data to a handful of clients (namely iOS and Android Apps).
Now, the constantly arising question is: from what point of view do we structure our JSON?
1) 'Client-centric':
The JSONs keys are named after the matching UI elements in the app. e.g.:
{
"label" : "This is a headline of a news article",
"textField" : "This is the text of a news article",
}
Pro:
Content of the apps can be changed without releasing new versions of the app. If you wanted to change the content of the UI label, it would look like this:
{
"label" : "This is a short abstract of a news article"
}
Also, it should be possible to have only one data model related to one view on the client side.
Contra:
Generates clutter on the server-side, as there must be the translation from data object name to UI element name
2) 'Data-centric'
The JSON keys are named after the data entity that delivers the data
{
"articleHeadline" : "This is a headline of a news article",
"articleText" : "This is the text of a news article"
}
Pro:
The JSON API says what it does. The key name reveals the content of the key.
Contra:
Generates clutter on the client-side, as there must be the translation from data object name to UI element name
A change in content will also change the name of the JSONs keys.
{
"articleAbstract" : "This is a short abstract of a news article"
}
This also requires a code change and deployment of all apps that use the API.