0

I'm working with WSO2 Micro Integrator (WSO2 MI) and trying to iterate over a JSON payload to extract values dynamically. However, I'm encountering the following error when using json-eval() inside a payloadFactory mediator

[2025-02-09 11:23:01,263] ERROR {PayloadFactoryMediatorFactory} - Invalid XPath expression for attribute expression : $.client_id org.jaxen.XPathSyntaxException: Expected: (identifier) Caused by: class org.jaxen.saxpath.XPathSyntaxException: $.client_id: 1: Expected: (identifier)

<iterate expression="json-eval($)">
<target>
<sequence>
<log level="custom">
<property expression="json-eval($.tokenEndpoint)" name="tokenEndpoint"/>
</log>
<!-- Set Headers & Body for Token Request -->
<property name="Content-Type" scope="transport" type="STRING" value="application/x-www-    form-urlencoded"/>
<property name="Accept" scope="transport" type="STRING" value="application/json"/>
<!-- Extract API Credentials -->
<property expression="json-eval($.tokenEndpoint)" name="TokenEndpoint" scope="default"     type="STRING"/>
<property expression="json-eval($.client_id)" name="client_id" scope="default" type="STRING"/>
<property expression="json-eval($.client_secret)" name="client_secret" scope="default" type="STRING"/>
<payloadFactory media-type="json">
<format>{"client_id":"$1","client_secret":"$2"}</format>
<args>
<arg evaluator="xml" expression="$.client_id"/>
 <arg evaluator="xml" expression="$.client_secret"/>
</args>
</payloadFactory>
<log level="full">
<property expression="json-eval($.body)" name="Token Request Payload"/>
</log>
</sequence>
</target>
</iterate>
1
  • Correctly format errors Commented Feb 10 at 4:04

1 Answer 1

1

Reason for the issue is using a JSON-Path expression with evaluator="xml". When evaluator="xml" its expecting a XPATH expression.

I don't see any requirement to use evaluators of type xml when the payload factory media type is JSON.

We can configure as follows.

<payloadFactory media-type="json">
<format>{"client_id":"$1","client_secret":"$2"}</format>
<args>
<arg evaluator="json" expression="$.client_id"/>
 <arg evaluator="json" expression="$.client_secret"/>
</args>
</payloadFactory>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.