hello everyone! I was curious to learn if there is...
# support
g
hello everyone! I was curious to learn if there is a way to write a user transformation to capture all event properties as a JSON column instead of the columns? this is the code I am using in the user transformation but wanted to check if I should proceed with it?
Copy code
export function transformEvent (event,metadata) {
if (event.type === "track") {
const properties = event.properties; 
JSON.stringify(properties);
}
return event;
}
I would like to get the properties for my event data in tracks table under one column in JSON format in my database. Currently all my properties appear as individual columns. I’m wondering if I can write a user transformation for this?
yes!
ideally a column called properties with the contents in a JSON format
Will this change all datetime properties and int properties to strings?
apologies if that is a silly question haha
p
Hi @gorgeous-balloon-24654, this should help with what you are trying to achieve, but will turn all properties into string:
Copy code
export function transformEvent (event,metadata) {
if (event.type === "track") {
    const properties = event.properties; 
    const stringProp=JSON.stringify(properties);
    event.properties=stringProp;
    }
return event;
}
g
ahh i see thanks! any way to ensure they are not strings but show up as a JSON column?
p
yes, have you tried the JSON column support feature? You can set it up using one the 3 ways listed in this doc. Once that is done, the column will have a different type based on the warehouse it's being sent to (snowflake, redshift etc..)
g
yes, that is the code I used as reference initially but my warehouse DB did not have one "Properties" column with the JSON grab
i used the #2 method - using a user transformation, listed in the doc and tried to do the same across all events
Copy code
export function transformEvent(event, metadata) {
  const meta = metadata(event);
    if (!event.integrations) event.integrations = {};
    event.integrations["SNOWFLAKE"] = {
      options: {
        jsonPaths: [event.properties]

    }
  }
  return event;
}
Will I have to declare the JSON columns at an event level and then use a user transformation? Is it possible to take all event properties from the payload for tracks calls and write them in my DB under one column?