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

如何在Jsonata中输出数组的序号与对应值?

问题:如何修改Jsonata表达式实现带序号的价格输出?

给定JSON数据

{
  "Account": {
    "Account Name": "Firefly",
    "Order": [
      {
        "OrderID": "order103",
        "Product": [
          {
            "Price": 34.45,
            "Quantity": 2
          },
          {
            "Price": 21.67,
            "Quantity": 1
          }
        ]
      }
    ]
  } 
}

当前Jsonata代码

(Account.Order.Product.(Price))

实际输出

[
  34.45,
  21.67
]

期望输出

1 : 34.45
2: 21.67

修改后的Jsonata表达式

$join(Account.Order.Product.(($index() + 1) & ": " & Price), "\n")

说明

  • $index():获取元素在数组中的起始索引(从0开始),加1后得到从1计数的序号
  • & ": " & Price:将序号、分隔符与价格拼接成单行字符串
  • $join(..., "\n"):用换行符把所有单行字符串连接起来,生成符合期望的文本格式

内容的提问来源于stack exchange,提问作者Shree

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.14 20:54:49