JSON in Flow Condition

Not applicable

Hello All,

I know in the <Condition> elements in a given flow, we can evaluate based on the value of a variable that is set in the context object. [e.g. context.setVariable("myTest", "1");]

If I set context variable to a JSON object, can we use the dot notation to evaluate a value in the JSON structure? As an example:

var jsonTree = { "bobo": { "page": 1, "paragraph": 2 } };

context.setVariable("jsonTree", jsonTree);

Then in our <Flow>, we'd try:

<Condition>jsonTree.bobo.page = 1</Condition>

I did a test locally and didn't see this working, but wanted to see if I am missing some consideration of this context object being a JSON structure as opposed to a string/number. The documentation shows the user of things like "proxy.pathsuffix"... I am pretty sure in this instance, it is just a reserved word, and not a dot notation type of object.

Any thoughts?

TIA,

Steve

1 7 1,414
7 REPLIES 7

Thank you @Stephan.Cossette for highlighting same. I can able to reproduce same. Seems like it's a bug.

var jsonTree = { "bobo": { "page": 1, "paragraph": 2 } };
context.setVariable("jsonTree", jsonTree);
context.setVariable("jsonTreeBoboPage", jsonTree.bobo.page);

Below condition works,

<Condition>jsonTreeBoboPage = 1</Condition>

But, below condition fails,

<Condition>jsonTree.bobo.page = 1</Condition>

I will follow up with our engineering team and keep you posted.

Hi Anil,

Thanks for the response... I was unsure if I could use a JSON object in the condition or not, and from your answer, it seems we should be able to, but it is not working as it should. I actually surprised that someone else didn't identify this bug prior to my discovery.

Any idea is this is going to be something that's going to be addressed within the next two weeks? Unfortunately I have a proof of concept to present, and if I cannot use the standard JSON/dot notation to do the condition check, I will need to come up with an alternative solution.

Thanks! Steve

adas
New Member

@Stephan.Cossette This is the expected behaviour. Condition evaluations will only work on flow variables. So in the above example you see that jsonTreeBoboPage = 1 work whereas trying to access the json object doesn't.

Ideally you would like to parse the json, extract the variable into a flow variable and then use that flow variable in the condition. That's how flow conditions were designed to work.

Hi Arghya,

Hrm... just seems wrong to not be able to evaluate a node on a JSON object using the dot notation... especially considering the documentation refers to pseudo-objects like "request.verb", "request.path", "proxy.pathsuffix", "request.header.accept", "response.status.code"... all of these appear to be nodes on a JSON object, not variables.

Regardless, this is going to complicate things considerably for my solution. This may not be a good fit to do in Apigee unless I do this as a Node.js API.

Thanks! Steve

adas
New Member

@Stephan.Cossette In your example, request.header.accept or proxy.pathsuffix, response.statuscode are flow variables namespaced to the corresponding object - request, proxy, response etc. Those are not nodes of a JSON object. I agree that this can complicate your implementation a little since you have to extract each node from your JSON into a variable and then use it in the flow conditions, but that's just one extra javascript policy that can extract and assign the variables. This is how the current implementation works. It was not designed to support JSON or XML or other objects out of the box using the object.element notation.

Not applicable

@Anil Sagar, @arghya das

yes, this feature would help us a lot, because for our requirement i need to use the XML object in condition. That's not possible today (not working for me).

Could you please let me know, Is this feature is being addressed to apigee engineering and any patch/new version is going to be release?

@Stephan.Cossette : Thanks for highlighting this issue.

Regards,

Ch.Venkat

Not applicable

Is this bug fixed? Can i use dot notation in condition in xml.