Thalweg · API reference ← Main docs

make_to_json_udf

Function make_to_json_udf 

Source
pub fn make_to_json_udf() -> ScalarUDF
Expand description

to_json(<any>) -> STRING — serialise an Arrow value of any type to a JSON string.

The symmetric counterpart of make_get_json_object_udf (a JSON reader): this is the JSON writer silver-lane authors need when the decoder produced a native Struct/List/Map for a column whose sink target is declared STRING. Without it, the only unblock is CAST(NULL AS VARCHAR) — data loss disguised as a hotfix. See docs/blueprints/decode-codec-learnings.md §4 and how-a-sink-should-work.md §8.6.

  • Accepts any Arrow input type (Signature::any(1)) — coercion cannot handle Struct/List/Map, so the argument is passed through un-coerced.
  • Delegates to arrow-json’s own encoder (make_encoder), the canonical Arrow JSON writer, so shape coverage (Struct, List, Map, Dictionary, every primitive) matches the ecosystem for free — no hand-rolled value walk.
  • SQL NULL round-trips as SQL NULL, not the JSON literal "null", matching Spark/Hive to_json semantics.
  • A scalar input yields its JSON scalar text: to_json(42)42, to_json('foo')"foo" (note the JSON double-quoting on strings).