Question & Answer
Question
How to use XPath with JSON messages in Java nodes
Answer
On Demand Consulting
Author: Volodymyr Sitarchuk
What will be equivalent for
java.util.List idList= (java.util.List ) inMessage.getRootElement().evaluateXPath("//TicketNumber");
String value = ((MbElement) idList.get(0)).getValueAsString();
for JSON input ?
Unfortunately XPath does not work with JSON
It is necessary to know the exact path to the element to get its value:
String value = inMessage.getRootElement().getLastChild().getFirstElementByPath("/JSON/Ticket/TicketNumber").getValueAsString();
Author: Volodymyr Sitarchuk
What will be equivalent for
java.util.List idList= (java.util.List ) inMessage.getRootElement().evaluateXPath("//TicketNumber");
String value = ((MbElement) idList.get(0)).getValueAsString();
for JSON input ?
Unfortunately XPath does not work with JSON
It is necessary to know the exact path to the element to get its value:
String value = inMessage.getRootElement().getLastChild().getFirstElementByPath("/JSON/Ticket/TicketNumber").getValueAsString();
[{"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Product":{"code":"SSQTW3","label":"IBM On Demand Consulting for Hybrid Cloud"},"Component":"","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"All Versions","Edition":"","Line of Business":{"code":"","label":""}}]
Was this topic helpful?
Document Information
More support for:
IBM On Demand Consulting for Hybrid Cloud
Software version:
All Versions
Document number:
771873
Modified date:
16 March 2019
UID
ibm10771873
Manage My Notification Subscriptions