Skip to content

Instantly share code, notes, and snippets.

@dankerizer
Last active September 5, 2024 04:47
Show Gist options
  • Save dankerizer/cd7b45bdc862f5a82639aaac5a6db599 to your computer and use it in GitHub Desktop.
Save dankerizer/cd7b45bdc862f5a82639aaac5a6db599 to your computer and use it in GitHub Desktop.
Convert Metabase to any Array Object
export type MetabaseDataProps = {
data: DataProps;
json_query: JSONQuery;
status: string;
}
export type DataProps = {
rows: Array<Array<number | string>>;
cols: ColProps[];
insights: null;
results_timezone: string;
}
export type ColProps = {
display_name: string;
source: string;
field_ref: Array<FieldRefClass | string>;
name: string;
base_type: string;
effective_type: string;
}
export type FieldRefClass = {
"base-type": string;
}
export type JSONQuery = {
}
export function convertMetabaseObjects<T = Record<string,unknown>[]>(data:DataProps) {
const columns = data.cols.map(col => col.name);
return data.rows.map(row => {
const obj = {};
columns.forEach((col, index) => {
obj[col] = row[index];
});
return obj as T;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment