跳至主要內容

T-JSON 批次 API

本頁整理的是會產生或處理 T-JSON 文字的非串流 API。可透過上方語言 tabs 在 Python、JavaScript 與 Rust 之間切換。

批次解析 API 依然會自動偵測 T-TOONT-JSONtyped_unit 輸入。這裡的分類是依照 T-JSON 的使用情境來整理,不代表這些函式只能處理 T-JSON。

套件:ttoon

讀取 T-JSON 批次文字

loads(text, mode=None) -> object

  • T-JSONT-TOONtyped_unit 解析為 Python 原生物件
  • mode 只影響 T-TOON 解析路徑

read_arrow(text) -> pyarrow.Table

  • 將批次文字解析為 pyarrow.Table
  • 自動偵測格式
  • 輸入必須是由統一物件組成,且欄位為 scalar 的列表

寫出 T-JSON 批次文字

to_tjson(obj, binary_format=None) -> str

  • 將 Python 物件序列化為 T-JSON 文字
  • 不接受 Arrow / Polars 輸入

stringify_arrow_tjson(obj, binary_format=None) -> str

  • pyarrow.Tablepyarrow.RecordBatchpolars.DataFrame 序列化為 T-JSON list-of-objects

轉碼為 T-JSON

ttoon_to_tjson(text, *, mode="compat", binary_format=None) -> str

  • 僅透過 Rust IR 將 T-TOON 直接轉成 T-JSON
  • mode"compat"(預設)或 "strict"

T-JSON 批次選項

參數APIs預設值
binary_formatto_tjson, stringify_arrow_tjson, ttoon_to_tjson"hex", "b64""hex"
modeloads, ttoon_to_tjson"compat", "strict""compat"

相關工具

  • detect_format(text) -> str 另見 格式偵測
  • TranscodeError 的型別不會因目標批次格式不同而改變

相關頁面