Page Contents


Various LoopBack methods accept type descriptions, for example remote methods and  dataSource.createModel().

The following table summarizes LoopBack’s data types.

Type Description Example
any Any type, including array, object, Date, or GeoPoint Any of: true, 123, "foo", [ "one", 2, true ]

JSON array

See Array types below.

[ "one", 2, true ]
Boolean JSON Boolean true
buffer Node.js Buffer object
new Buffer(42);
date JavaScript Date object

new Date("December 17, 2003 03:24:00");


LoopBack GeoPoint object

new GeoPoint({lat: 10.32424, lng: 5.84978});
null JSON null null
number JSON number



JSON object or any type

See Object types below.

{ "firstName": "John", "lastName": "Smith", "age": 25 }
String JSON string "StrongLoop"

In general, a property will have undefined value if no explicit or default value is provided.

Array types

LoopBack supports array types as follows:

  • {emails: [String]}
  • {"emails": ["string"]}
  • {"emails": [{"type": "string", "length": 64}]}
  • {"emails": "array"} (a shorthand notation for {"emails": ["any"]})

Array of objects

Define an array of objects as follows (for example):

"Address": {
  "type": [
  "required": true

Object types

Use the Object type when you need to be able to accept values of different types, for example a string or an array.

A model often has properties that consist of other properties. For example, the user model can have an address property that in turn has properties such as streetcitystate, and zipCode. LoopBack allows inline declaration of such properties, for example:

var UserModel = {
    firstName: String,
    lastName: String,
    address: {
        street: String,
        city: String,
        state: String,
        zipCode: String

The value of the address is the definition of the address type, which can be also considered an “anonymous” model.

If you intend to reuse the address model, define it independently and reference it in the user model. For example:

var AddressModel = {
    street: String,
    city: String,
    state: String,
    zipCode: String

var Address = ds.define('Address', AddressModel);

var UserModel = {
        firstName: String,
        lastName: String,
        address: 'Address',  // or address: Address

var User = ds.define('User', UserModel);