Nested Parameters

Parameter values can be any valid JSON value, including nested objects. Let's update our action to use child properties of the event parameters.

  1. Create the hello-person action with the following source code.

     function main(params) {
         return {payload:  'Hello, ' + params.person.name + ' from ' + params.person.place};
     }
     ic fn action create hello-person hello-person.js

    Now the action expects a single person parameter to have fields name and place.

  2. Invoke the action with a single person parameter that is valid JSON.

    ic fn action invoke --result hello-person -p person '{"name": "Elrond", "place": "Rivendell"}'

    The result is the same because the CLI automatically parses the person parameter value into the structured object that the action now expects:

    {
        "payload": "Hello, Elrond from Rivendell"
    }

Last updated

Was this helpful?