0

I have a snowflake event table created. The below code inserts log records into event table.

import snowflake.snowpark as snowpark
import logging
def main(session: snowpark.Session):
    LOGGER = logging.getLogger('snowflake.snowpark.session')
    dict1 = {"abc": "123", "cdf": "345"}

    LOGGER.info(dict1)
    return f'Testing the Logging'

Now this dict is being written as string in snowflake event table under 'VALUE' column which is VARIATNT. "{'abc': '123', 'cdf': '345}" How can make this as json object instead of string using the above loggers

Tried different ways but nothing helped

1 Answer 1

0

Use json.dumps() to log a proper JSON object: import logging import json

import logging
import json
dict1 = {"abc": "123", "cdf": "345"} 
LOGGER.info(json.dumps(dict1))
# ✅ logs as valid JSON for Snowflake VARIANT

This ensures the log is stored as a JSON object in Snowflake, not a plain string.

Sign up to request clarification or add additional context in comments.

2 Comments

Tried this way also but it's coming as "{\"abc\": \"123\", \"cdf\": \"345\"}" in variant column in snowflake event table
Don't use json.dumps(dict1) — it converts the dict to a string. Use LOGGER.info(dict1) directly to log as a proper JSON object in Snowflake VARIANT.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.