Represent json string in Text column in structured format

Hi @Hugoman, and welcome to the SeaTable forum!
If you use SeaTable self-hosted, you can pretty easily install the python pipeline if it’s not already done. Then, you can use this script:

import json
from seatable_api import Base, context

base = Base(context.api_token,context.server_url)
base.auth()

TABLE_NAME = 'Message List'
RAW_JSON_COL = 'Event Message'
FORMATTED_JSON_COL = 'Formatted Event Message'

curr_row = context.current_row
print(curr_row)

json_data = curr_row.get(RAW_JSON_COL).replace('\\','').replace('\n', ' ').replace('\r', '')
print(json_data)

obj = json.loads(json_data)
print(obj)

json_formatted_str = json.dumps(obj, indent=4)
print(json_formatted_str)
base.update_row(TABLE_NAME, curr_row['_id'], {FORMATTED_JSON_COL : json_formatted_str})

You’ll have to modify the content of the variables in uppercase at the beginning of the script and add a second longtext column (or try to modify your existing Event Message column which should work, but I didn’t test it.
The script can be launched using a button or an automation.

Bests,
Benjamin


I love spending time gathering information and explaining solutions to help you solve your problems. I spend… quite a bit of time on it :sweat_smile: .If you feel grateful for the help I’ve given you, please don’t hesitate to support me. I am also available for paid services (scripts, database architecture, custom development, etc.).

1 Like