JOLT 中的 charAt() 函数,用于根据位置提取字符

问题描述 投票:0回答:1

我在下面的输出中得到

null

规格

[
  {
    "operation": "shift",
    "spec": {
      "f($;$ = $.A.charAt(2)  )": "charAt"
    }
  }
]

输入:

[
  {
    "A": "Active"
  }
]

预期产出:

{
  "charAt": "t"
}
json transformation jolt
1个回答
0
投票

没有这样的函数叫做 charAt,此外这些函数不能在 shift 转换中使用。

您可以使用 modify 转换规范以及 elementAt 函数,例如

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": {
        "A": "=split('',@(1,&))", // convert the string into an array of letters which constructs it
        "charAt": "=elementAt(2,@(1,A))"
      }
    }
  },
  {
    "operation": "remove",
    "spec": {
      "*": {
        "A": "" // get rid of the reformed array
      }
    }
  }
]

它将返回文字

t
中的字母
A
,只要索引从
2
开始
网站上的
demo

http://jolt-demo.appspot.com/

© www.soinside.com 2019 - 2024. All rights reserved.