# Transform Typescript query of user sessions from @dynatrace-sdk/client-classic-environment-v1 in Notebooks and Dashboards to JSON

**URL:** <https://community.dynatrace.com/t/transform-typescript-query-of-user-sessions-from-dynatrace-sdk-client-classic-environment-v1-in-notebooks-and-dashboards-to-json/41003>\
**Category:** DQL\
**Tags:** dql, typescript, usql, notebooks, dashboards, user-sessions\
**Created:** [August 2, 2023, 6:13pm UTC](https://community.dynatrace.com/t/transform-typescript-query-of-user-sessions-from-dynatrace-sdk-client-classic-environment-v1-in-notebooks-and-dashboards-to-json/41003 "2023-08-02T18:13:12Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![heybeckerj](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/heybeckerj/32/22189_2.png) [@heybeckerj](https://community.dynatrace.com/u/heybeckerj)\
**Post date:** [August 3, 2023, 5:38pm UTC](https://community.dynatrace.com/t/transform-typescript-query-of-user-sessions-from-dynatrace-sdk-client-classic-environment-v1-in-notebooks-and-dashboards-to-json/41003/4 "2023-08-03T17:38:38Z")

</div>

Thank you&nbsp;[@Fin\_Ubels](https://community.dynatrace.com/user/47376)&nbsp;and&nbsp;[@rkdy](https://community.dynatrace.com/user/54274)&nbsp;, 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:

```javascript
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:

 ![heybeckerj_0-1691084393703.png](https://global.discourse-cdn.com/dynatrace/original/3X/f/0/f048b75d2e3d613ea7059c886c1af4403dc502b9.png)

But, now there are 3 documentated ways to do this. I’ve learned so much! 👍💪🛠🤘🚀

---

_[View the full topic](https://community.dynatrace.com/t/transform-typescript-query-of-user-sessions-from-dynatrace-sdk-client-classic-environment-v1-in-notebooks-and-dashboards-to-json/41003)._
