Public
Edited
Nov 19
Insert cell
Insert cell
Insert cell
function cleanObjectNames(rawData) {
return rawData.map(obj => {
return Object.keys(obj).reduce((acc, key) => {
// Create a new key by lowercasing, replacing spaces and hyphens with underscores,
// and removing non-alphanumerical characters
const newKey = key
.toLowerCase()
.replace(/[\s-]+/g, '_') // Replace spaces and hyphens with underscores
.replace(/[^a-z0-9_]/g, ''); // Remove non-alphanumerical characters
// Trim leading and trailing underscores
const trimmedKey = newKey.replace(/^_+|_+$/g, '');

acc[trimmedKey] = obj[key]; // Assign the original value to the new key
return acc;
}, {});
});
}
Insert cell
function convertDataTypes(dataArray, keyFormats) {
return dataArray.map(item => {
let newItem = { ...item };
for (const [key, formatFunction] of Object.entries(keyFormats)) {
if (newItem.hasOwnProperty(key)) {
newItem[key] = formatFunction(newItem[key]);
}
}
return newItem;
});
}
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more