@@ -332,6 +332,9 @@ class Parser(parser.Parser):
332332 "FROM_UTF8" : lambda args : exp .Decode (
333333 this = seq_get (args , 0 ), replace = seq_get (args , 1 ), charset = exp .Literal .string ("utf-8" )
334334 ),
335+ "JSON_FORMAT" : lambda args : exp .JSONFormat (
336+ this = seq_get (args , 0 ), options = seq_get (args , 1 ), is_json = True
337+ ),
335338 "LEVENSHTEIN_DISTANCE" : exp .Levenshtein .from_arg_list ,
336339 "NOW" : exp .CurrentTimestamp .from_arg_list ,
337340 "REGEXP_EXTRACT" : build_regexp_extract (exp .RegexpExtract ),
@@ -582,13 +585,27 @@ class Generator(generator.Generator):
582585 "with" ,
583586 }
584587
588+ def jsonformat_sql (self , expression : exp .JSONFormat ) -> str :
589+ this = expression .this
590+ is_json = expression .args .get ("is_json" )
591+
592+ if this and not (is_json or this .type ):
593+ from sqlglot .optimizer .annotate_types import annotate_types
594+
595+ this = annotate_types (this , dialect = self .dialect )
596+
597+ if not (is_json or this .is_type (exp .DataType .Type .JSON )):
598+ this .replace (exp .cast (this , exp .DataType .Type .JSON ))
599+
600+ return self .function_fallback_sql (expression )
601+
585602 def md5_sql (self , expression : exp .MD5 ) -> str :
586603 this = expression .this
587604
588605 if not this .type :
589606 from sqlglot .optimizer .annotate_types import annotate_types
590607
591- this = annotate_types (this )
608+ this = annotate_types (this , dialect = self . dialect )
592609
593610 if this .is_type (* exp .DataType .TEXT_TYPES ):
594611 this = exp .Encode (this = this , charset = exp .Literal .string ("utf-8" ))
@@ -630,6 +647,7 @@ def bracket_sql(self, expression: exp.Bracket) -> str:
630647 expression .this ,
631648 expression .expressions ,
632649 1 - expression .args .get ("offset" , 0 ),
650+ dialect = self .dialect ,
633651 ),
634652 0 ,
635653 ),
@@ -639,7 +657,7 @@ def bracket_sql(self, expression: exp.Bracket) -> str:
639657 def struct_sql (self , expression : exp .Struct ) -> str :
640658 from sqlglot .optimizer .annotate_types import annotate_types
641659
642- expression = annotate_types (expression )
660+ expression = annotate_types (expression , dialect = self . dialect )
643661 values : t .List [str ] = []
644662 schema : t .List [str ] = []
645663 unknown_type = False
0 commit comments