ConvertKeysToTableFieldFormat

Convert object keys to match table keys. Use when mapping object/collection to table (grid) field. (Array of objects/collections is also supported). Example: Input: { "Engine": "val1", "Max Results": 13892378, "Key_With^Special (characters)": true } Output: { "engine": "val1", "maxresults": 13892378, "keywithspecialcharacters": true }

javascript · Filters And Transformers

Source

// convert a specific key
function stripToCliName(str) {
  return str.substr(0, 255).replace(/[\W\s\\&$#@%?!_*;׳()^]/g, '').toLowerCase();
}

// convert object keys
function convertObject(obj) {
    var res = {};
    Object.keys(obj).forEach(function(key) {
        res[stripToCliName(key)] = obj[key];
    });
    return res;
}

var value = args.value;

if (typeof value !== "object") {
    return {
        ContentsFormat: formats.text,
        Type: entryTypes.error,
        Contents: 'Invalid input. Expected object/collection, got: ' + value
    };
}

if (Array.isArray(value)) {
    return value.map(convertObject);
}

return convertObject(value);



README

Converts object keys to match table keys. Use this when mapping object/collection to table (grid) field.
(An array of objects/collections is also supported).

Example:

  • Input: { “Engine”: “val1”, “Max Results”: 13892378, “Key_With^Special (characters)”: true }
  • Output: { “engine”: “val1”, “maxresults”: 13892378, “keywithspecialcharacters”: true }

Script Data


Name Description
Script Type javascript
Tags transformer

Inputs


Argument Name Description
value The object to convert.

Outputs


There are no outputs for this script.