You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Google Workflow中读取Firestore文档的原始JSON(不含元数据)

在Google Workflow中读取Firestore文档的原始JSON

调用Firestore的googleapis.firestore.v1.projects.databases.documents.get接口时,返回结果会包含元数据,且字段值会被类型包装(比如stringValue、integerValue)。要得到和原始JSON一致的结构,需要在Workflow中手动转换这些字段。

修改后的Workflow示例

- get_document:
    call: googleapis.firestore.v1.projects.databases.documents.get
    args:
      name: ${"projects/" + project_id + "/databases/(default)/documents/" + doc_path}
    result: r
- convert_to_raw_json:
    assign:
      raw_data: {}
    for:
      value: "${r.fields}"
      index: key
      steps:
        - assign_value:
            switch:
              - condition: "${value.stringValue != null}"
                assign:
                  raw_data[key]: "${value.stringValue}"
              - condition: "${value.integerValue != null}"
                assign:
                  raw_data[key]: "${int(value.integerValue)}"
              - condition: "${value.booleanValue != null}"
                assign:
                  raw_data[key]: "${value.booleanValue}"
              - condition: "${value.doubleValue != null}"
                assign:
                  raw_data[key]: "${value.doubleValue}"
              # 若需要处理数组、嵌套对象等类型,可添加对应逻辑
              # - condition: "${value.arrayValue != null}"
              #   assign:
              #     raw_data[key]: "${value.arrayValue.values}"
              # - condition: "${value.mapValue != null}"
              #   assign:
              #     raw_data[key]: "${value.mapValue.fields}"
- use_raw_data:
    log: "${raw_data}" # 此处的raw_data即为原始JSON格式的数据

说明

  • 通过for循环遍历返回结果中的fields对象,针对不同的字段类型(字符串、整数、布尔值等)提取对应的值,组装成raw_data对象。
  • 根据你实际存储的字段类型,补充对应的类型判断逻辑即可。比如如果有数组或嵌套对象,需要额外处理arrayValue和mapValue。

内容的提问来源于stack exchange,提问作者Daniel De León

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 21:01:20