Thank you @Fin_Ubels and @rkdy , both of these great suggestions!
I managed to find a way to reconstruct a table form the result by iterating through the 2D array object as well as the columnNames array object instead of having the hardcode any headers. This way it is more dynamic.
Example:
import { rumUserSessionsClient } from "@dynatrace-sdk/client-classic-environment-v1";
function convertTableToJSON(headers,table) {
// extract header as keys
let keys = headers;
// create JSON objects from the remaining data
let json = table.map(row => {
let obj = {};
// add each element of the row to the object with the corresponding key
row.forEach((value, index) => {
obj[keys[index]] = value;
});
return obj;
});
return json;
}
export default async function () {
const response = await rumUserSessionsClient.getUsqlResultAsTable({
query: "SELECT DISTINCT city, country FROM usersession",
startTimestamp: 1688184000000 ,
endTimestamp: 0,
pageOffset: 0
});
console.log(response);
const jsonData = convertTableToJSON(response.columnNames,response.values);
console.log(jsonData);
return jsonData;
}
Result:
But, now there are 3 documentated ways to do this. I’ve learned so much! ![]()
![]()
![]()
![]()
![]()
