I`ve extracted an array from a Json Input and i want to make referente to one elemente on array, when i try to do this i can see that Apigee is trying to make referente to a new variable.
as you can see below, i have the "jsonPath.result" as an array, but in assignMessage i try to read "jsonPath.result[2]", its a blank value and should be "VW".
How can i referente do specific elements inside an array?
Solved! Go to Solution.
Thanks for the screenshot, that makes it very clear.
Apigee context variables are strongly typed: they can be of type Message, boolean, String, and so on.
I believe the extraction you've done has populated a variable with a string, which looks like this:
["Ford", "BMW", "VW"]
I don't know for sure, though. Your JavaScript is the thing that is storing this variable, probably with a statement like this:
context.setVariable('jsonPath.result', SOMETHING);
...and I'm guessing the SOMETHING resolves to a string.
Anyway, within the Apigee DSL, it is not possible to coerce a string to behave as an Array, or to implicitly cast a string into an array. Using a name like "jsonPath.result[2]" will not do what you hope.
The way to get access to the 2nd item in the array is
screen-shot-2021-03-19-at-153307.png
missing screen
Thanks for the screenshot, that makes it very clear.
Apigee context variables are strongly typed: they can be of type Message, boolean, String, and so on.
I believe the extraction you've done has populated a variable with a string, which looks like this:
["Ford", "BMW", "VW"]
I don't know for sure, though. Your JavaScript is the thing that is storing this variable, probably with a statement like this:
context.setVariable('jsonPath.result', SOMETHING);
...and I'm guessing the SOMETHING resolves to a string.
Anyway, within the Apigee DSL, it is not possible to coerce a string to behave as an Array, or to implicitly cast a string into an array. Using a name like "jsonPath.result[2]" will not do what you hope.
The way to get access to the 2nd item in the array is