Shreejit Malshikhare
Shreejit Malshikhare

Reputation: 25

How to import CSV files in Anypoint studio and convert them into JSON format?

I want to use HTTP Listener in my flows, and import csv files in Anypoint studio as input and convert them into JSON. Please help me.

Upvotes: 0

Views: 441

Answers (2)

satish chennupati
satish chennupati

Reputation: 2650

you can just use a transform message and convert payload to json.

as you can see i am reading a file called address.csv. enter image description here

in the transform message you can simple right

enter image description here

and in my logger you can see that contents of file converted to json

enter image description here

note ------------------------------------------------- if you want to pick a file in middle of a flow with a http listener you can always use Message-Requester module

here is how the code will look like

    <file:connector name="file-connector-config" autoDelete="false" streaming="true" validateConnections="true" doc:name="File" />
    <http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" basePath="/requester" doc:name="HTTP Listener Configuration" />
     <flow name="muleRequester">
         <http:listener config-ref="HTTP_Listener_Configuration" path="/requester" doc:name="HTTP" />
        <logger message="Invoking Mule Requester" level="INFO" doc:name="Logger" />
        <mulerequester:request resource="file://src/main/resources/in/ReadME.txt?connector=file-connector-config" doc:name="Retrieve File" returnClass="java.lang.String" />
        <logger message="Payload after file requester #[payload]" level="INFO" doc:name="Logger" />
        </flow>

refer link --> https://dzone.com/articles/mule-reading-file-in-the-middle-of-a-flow-using-mu

Upvotes: 2

utechtzs
utechtzs

Reputation: 1023

Maybe I'm misunderstanding the question, but if you'd like the http listener kick off the flow, then to load the file, you'll need a groovy script.

<scripting:component doc:name="Groovy">
    <scripting:script engine="Groovy"><![CDATA[return new File("C:\test.csv").getText("UTF-8");]]></scripting:script>
</scripting:component>

Upvotes: 1

Related Questions