Forum Discussion

npise's avatar
npise
New Contributor II
6 years ago
Solved

Build json body- for POST request

How to build raw POST body using mapper? Need to achieve below

{
“conditions”: [
{
“name”: “learningevent_id”,
“operator”: “==”,
“value”: “12345”
}
]
}

I am able to achieve its missing [ ]

Expression for mapper below

  • Hi @npise,

    You could put sl.ensureArray($requestBody.conditions) in an expression in a Mapper after the one you described, and assign it to the $requestBody.conditions target path.

    Alternatively, if you want to achieve everything in one Mapper, you can put sl.ensureArray({}.extend({name:“learningevent_id”, operator:“==”,value:$learningevent_id})) in the expression and assign it to the $requestBody.conditions target path.

    BR,
    Dimitri

2 Replies

  • Hi @npise,

    You could put sl.ensureArray($requestBody.conditions) in an expression in a Mapper after the one you described, and assign it to the $requestBody.conditions target path.

    Alternatively, if you want to achieve everything in one Mapper, you can put sl.ensureArray({}.extend({name:“learningevent_id”, operator:“==”,value:$learningevent_id})) in the expression and assign it to the $requestBody.conditions target path.

    BR,
    Dimitri

    • npise's avatar
      npise
      New Contributor II

      Thank you so much this worked!!

      i was able to achieve that in one input expression
      sl.ensureArray({}.extend({name:‘learningevent_id’, operator:“==”,value:$learningevent_id}))