[英]In a Step Function, how do I convert an array of scalars into an array of dictionaries?
Input of the step - How to Modify the input of the step in a step function from this:步骤的输入 - 如何修改步骤 function 中的步骤输入:
{
"A": "X",
"B": "Y",
"C": [
"Z1",
"Z2",
"Z3"
]
}
and convert into this并转换成这个
{
"A": "X",
"B": "Y",
"C": [
{
"Z": "Z1"
},
{
"Z": "Z2"
},
{
"Z": "Z3"
}
]
}
using ASL or C# CDK.使用 ASL 或 C# CDK。 I tried to convert an array of strings to an array of elements using:
我尝试使用以下方法将字符串数组转换为元素数组:
"Modify Input": {
"Type": "Pass",
"Parameters": {
"A": "$.A",
"B": "$.B",
"C": [
{
"Z": "States.array($.C)"
}
]
}
Append .$
to the key name if the value is a JsonPath substitution . Append.
.$
如果值为JsonPath 替换,则为键名。 Without it, Step Functions treats the value as a string literal.如果没有它,Step Functions 会将值视为字符串文字。 Use the
States.ArrayGetItem
intrinsic function to pick items at an index:使用
States.ArrayGetItem
内在 function在索引处选择项目:
{
"A.$": "$.A",
"B.$": "$.B",
"C": [
{ "Z.$": "States.ArrayGetItem($.C,0)" },
{ "Z.$": "States.ArrayGetItem($.C,1)" },
{ "Z.$": "States.ArrayGetItem($.C,2)" }
]
}
The CDK accepts these literal values. CDK 接受这些文字值。 It also provides the optional JsonPath class, which exposes methods for the intrinsic classes and lets you omit the
.$
from key names.它还提供了可选的JsonPath class,它公开了内部类的方法并允许您从键名中省略
.$
。 The CDK emits the same State Machine definition output either way.无论哪种方式,CDK 都会发出相同的 State 机器定义 output。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.