How to extract array using jsonPath Message Template function using AssignMessage Policy?

Assume the below incoming payload received to API proxy,

{
"plans":["100","101","102"],
"customerId":"123456789"
}

I would like to use jsonPath message template function to extract the plans and customerId values and populate it in Assign Message payload value. When i use the below policy I'm getting the first element in the array instead of complete array for plans.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="request">
    <DisplayName>create-request</DisplayName>
    <Properties/>
    <AssignVariable>
        <Name>paymentPlans</Name>
        <Template>{jsonPath($.plans[*],message.content)}</Template>
    </AssignVariable>
    <AssignVariable>
        <Name>customerId</Name>
        <Template>{jsonPath($.customerId,message.content)}</Template>
    </AssignVariable>
    <Set>
        <Verb>POST</Verb>
        <Payload contentType="application/json">
            {
        "plan": "{paymentPlans}",
        "Id":"{customerId}"
             }
</Payload>
    </Set>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage> 

The above policy resulted in

 {
"plan":"100",
"Id":"123456789"
} 

We are able to achieve the same using Extract and Assign message policy. Wanted to know can we achieve the same using message template function as well.

Any help would be appreciated. Thanks

Solved Solved
1 2 1,115
1 ACCEPTED SOLUTION

Yes, there is a known issue with the jsonPath function in Message Templates - you cannot request an array return value. When there is an array result, You always get the first element of the array.

The reference for this issue is b/132460133

The good? news is that this issue is already fixed. There will be a way for you to request an array value explicitly.

The bad news is that the fix is not yet released.

So, for now you need to use ExtractVariables - sorry!

View solution in original post

2 REPLIES 2

Yes, there is a known issue with the jsonPath function in Message Templates - you cannot request an array return value. When there is an array result, You always get the first element of the array.

The reference for this issue is b/132460133

The good? news is that this issue is already fixed. There will be a way for you to request an array value explicitly.

The bad news is that the fix is not yet released.

So, for now you need to use ExtractVariables - sorry!

Thank you @Dino