JSON Mule Collector Splitter

I have a JSON that looks something like the image below. I am trying to extract every single entry and push it to the queue. How can I extract each entry in a Mule? I am trying to use a collection splitter and a foreach loop, but I cannot figure out how to make this work.

{ "locations": { "record": [ { "id": 8817, "loc": "NEW YORK CITY" }, { "id": 2873, "loc": "UNITED STATES" }, { "id": 1501, "loc": "NEW YORK STATE" } ] } } 
+4
source share
3 answers

For this:

  • Convert a JSON object to a hierarchy of Java structures,
  • Retrieve the record list,
  • Split list.

Now in the Mule XML config:

 <json:json-to-object-transformer returnClass="java.util.Map" /> <expression-transformer expression="#[message.payload.locations.record]" /> <collection-splitter /> <!-- TODO: dispatch to queue --> 
+5
source

try this, not Map put List. This works great for me.

 <json:json-to-object-transformer returnClass="java.util.List" /> <expression-transformer expression="#[message.payload.locations.record]" /> <collection-splitter /> 
+1
source

I am adding another solution in which returnclass = "java.util.Map" works, please take a look at the code where you can put the same JSON into the body using the http method as POST when sending data from Fiddler or POST people - customer.

Here in this thread, I directly assign an expression to Splitter instead of using Expression Transformer. I use Any Point Studio to make it work.

  <flow name="mule-splitterFlow2" doc:name="mule-splitterFlow2"> <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP" path="splitterjson"/> <json:json-to-object-transformer returnClass="java.util.Map" doc:name="JSON to Object"/> <splitter expression="#[message.payload.locations.record]" doc:name="Splitter"> </splitter> <logger level="INFO" doc:name="Logger" message="#[message.payload]"/> </flow> 
+1
source

Source: https://habr.com/ru/post/1437287/


All Articles