Converters are pieces of javascript code that take the result from a query, process it into a custom array of objects and then pass it on to the template. Of course you can do some calculations, formattings and renamings there as well. Most of the time converters are needed when dealing with JSON responses from REST APIs, but they can be applied to SQL results as well.

Properties

Each converter entity consists of the following properties:

For various examples on how to use converters, refer to ourĀ List Of REST Examples.

Example Converters

Converter scaffold:

function convert(json) { // json is the result as json string
    var result = []; // the array-of-objects we will return
    var parsedJsonObject = JSON.parse(json); // parse json string
    var current, index; // loop variables
    for (index in parsedJsonObject) { // iterate through the result
        // only continue if this property is not inherited
        if (parsedJsonObject.hasOwnProperty(index)) {
            current = parsedJsonObject[index]; // current object
            result.push({ // add a converted object
                'Column 1 name': current.column1Name,
                'Column 2 name': current.column2Name
                // ...
            });
        }
    }
    return result; // return the converted result
}


Example converter for a facebook REST call that fetches all pages liked by the user:

function convert(json) {
    var result = [];
    var parsedJsonObject = JSON.parse(json);
    var current, index;
    for (index in parsedJsonObject) {
        if (parsedJsonObject.hasOwnProperty(index)) {
            current = parsedJsonObject[index];
            result.push({
                'Page name': current.name,
                'Date of pressing Like': PocketQuery.formatDate(current.created_time,'YYYY-MM-DD (dddd), hh:mm') + ' Uhr'
            });
        }
    }
    return result;
}