public/services/sheetServices.js
//Replace all space in json data keys
Replace all space in json data keys
Replace all space in json data keys
function formatJSON(json, columns, timezone = false){
  const dateColumns = columns.filter(c => (c.type === "date"))
  json.forEach(function(e, i) {
    Object.keys(e).forEach(function(key) {
      var val = e[key],
      newKey = key.replace(/\s+/g, '_');
      if (timezone && dateColumns.filter(c => (newKey === c.name)).length > 0) {
        val = moment(val).tz(timezone).format()
      }
      delete json[i][key];
      json[i][newKey] = val;
    });
  });
  return json;
}
function formatJSON ( json , columns , timezone = false ) { const dateColumns = columns . filter ( c => ( c . type === "date" ) ) json . forEach ( function ( e , i ) { Object . keys ( e ) . forEach ( function ( key ) { var val = e [ key ] , newKey = key . replace ( / \s+ / g , '_' ) ; if ( timezone && dateColumns . filter ( c => ( newKey === c . name ) ) . length > 0 ) { val = moment ( val ) . tz ( timezone ) . format ( ) } delete json [ i ] [ key ] ; json [ i ] [ newKey ] = val ; } ) ; } ) ; return json ; }
Replace all space in json data keys
Replace all space in json data keys
// Iterate over array // Iterate over the keys of object // Copy the value // check date object and manage timezone // Remove key-value from object // Add value with new key