Skip to content

Instantly share code, notes, and snippets.

@leo-bianchi
Created November 4, 2019 17:24
Show Gist options
  • Save leo-bianchi/665b7d0b093d81f7f628c8a758e299e4 to your computer and use it in GitHub Desktop.
Save leo-bianchi/665b7d0b093d81f7f628c8a758e299e4 to your computer and use it in GitHub Desktop.
Build a custom object from another object.
/**
* Build a custom json template from another json.
*
* @param {Object} myObject - Object to be build
* @returns {Object} Builded JSON
* @module buildJson
*/
function buildJson(myObject) {
myObject = Object.keys(myObject).map(function(key, index) {
let newObject = {
'name': key,
'label': key.toUpperCase(),
'value': myObject[key].replace(/\uFFFD/g, ''), // Replace broken characters
'order': index
};
return newObject;
});
return myObject;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment