Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to add new key/value to InputPath?

I need to expand InputPath of Step Functions state with a new property without changing the structure of the initial InputPath.

For instance, my InputPath looks like:

{
    "key1": "value1",
    "key2": "value2"
}

I need to add here a new pair of key/value and pass this to Lambda. Thus, what I want to have is:

{
   "key1": "value1",
   "key2": "value2",
   "key3": "value3"
}

But I haven't found the way how to implement this. What I was able to do is to change the structure of InputPath using Parameters:

"InputPath": "$",
"Parameters": {
    "input.$": "$",
    "newValue": "value3"
}

So I get JSON with the following structure:

{
    "input": {
        "key1": "value1",
        "key2": "value2"
    },
    "key3": "value3"
}

It's not a big problem, but I wonder if there is a way to keep a flat structure of InputPath and not to add new attributes (like "input" in my example).

UPD: I'm aware that it can be implemented using Pass states, but state machine is going to become too massive then.

like image 568
pdanchenko Avatar asked Jan 17 '26 07:01

pdanchenko


1 Answers

If you do not know the input parameters, you can use JsonMerge intrinsic function

States.JsonMerge($, States.StringToJson(States.Format('\\{\"{}\": \"{}\"\\}', $.key2, $.value3)), false)
like image 135
vikas patidar Avatar answered Jan 19 '26 19:01

vikas patidar