Cast JSON to varchar with Trino

5.7k Views Asked by At

I'm trying to cast JSON object from table column to varchar with Trino I tried with these docs here but every time throws an error. https://trino.io/docs/current/functions/json.html If someone can post an example how I can make that it will be great.

1

There are 1 best solutions below

1
On

Use json_format/json_parse to handle json object conversions instead of casting:

select json_parse('{"property": 1}') objstring_to_json, json_format(json '{"property": 2}') jsonobj_to_string

Output:

objstring_to_json jsonobj_to_string
{"property":1} {"property":2}