Show TOC

JSON ModelLocate this document in the navigation structure

The JSON model can be used to bind controls to JavaScript object data, which is usually serialized in the JSON format.

The JSON model is a client-side model and, therefore, intended for small data sets, which are completely available on the client. The JSON model does not support mechanisms for server-based paging or loading of deltas. It supports, however, two-way binding. Also, client-side models like the JSON model have no built-in support for sending data back to the server. The apps have to use, for example, model.getData() and jQuery.ajax() to send updated data to the server.

To instantiate a JSON model, use the following code:
var oModel = new sap.ui.model.json.JSONModel();

After the instance has been created, there are different options to get the data into the model.

The easiest option is to set data by using the setData method:
oModel.setData({
    firstName: "Peter",
    lastName: "Pan"
});
Note The correct JSON notation uses double quotes for the keys and string values.
Usually, you do not define your data inline in the application but load it from a server-side service using an XHR request. The JSON model, however, also has a loadData method, which loads the JSON data from the specified URL asynchronously and applies it to the model:
oModel.loadData("data.json");