const data =
{
"ColumnMetadata": [
{
"isCaseSensitive": true,
"isCurrency": false,
"isSigned": false,
"label": "dealer_name",
"length": 0,
"name": "dealer_name",
"nullable": 1,
"precision": 255,
"scale": 0,
"schemaName": "raw_data",
"tableName": "xxxxxxxxxxxxxxxxx",
"typeName": "varchar"
},
{
"isCaseSensitive": true,
"isCurrency": false,
"isSigned": false,
"label": "city",
"length": 0,
"name": "city",
"nullable": 1,
"precision": 255,
"scale": 0,
"schemaName": "raw_data",
"tableName": "xxxxxxxxxxxxxxxxx",
"typeName": "varchar"
},
{
"isCaseSensitive": false,
"isCurrency": false,
"isSigned": true,
"label": "vehicle_count",
"length": 0,
"name": "vehicle_count",
"nullable": 1,
"precision": 19,
"scale": 0,
"schemaName": "",
"tableName": "",
"typeName": "int8"
}
],
"Records": [
[
{
"stringValue": "Grand Prairie Ford Inc."
},
{
"stringValue": "Grand Prairie"
},
{
"longValue": 18
}
],
[
{
"stringValue": "Currie Motors Ford of Valpo"
},
{
"stringValue": "Valparaiso"
},
{
"longValue": 16
}
]
],
"TotalNumRows": 2
}
const buildParameterSets = (res) => {
let columns = res.ColumnMetadata.map((c) => [c.name, c.typeName] );//get type and name of column
let data = res.Records.map((r) => {
let arr = r.map((v, i) => {
if (columns[i][1].includes("int")) {
return {
name: columns[i][0],
value: {
longValue: Object.values(v)[0]
}
}
} else {
return {
name: columns[i][0],
value: {
stringValue: Object.values(v)[0]
}
}
}
});
return arr;
});
return data;
};
console.log(buildParameterSets(data));