你可以這樣做。
<flow name="csv-to-jsonFlow">
<file:inbound-endpoint path="/src/main/resources/csv" connector-ref="File" responseTimeout="10000" doc:name="File">
<file:filename-regex-filter pattern=".*csv" caseSensitive="true"/>
</file:inbound-endpoint>
<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
payload]]></dw:set-payload>
</dw:transform-message>
<object-to-string-transformer doc:name="Object to String"/>
<logger message="#[payload]" level="INFO" doc:name="Logger"/>
</flow>
文件示例:
name,age,gender
janos,29,male
juan,40,male
pedro,22,male
carla,34,female
jose,30,male
anne,25,female
rey,33,male
joyce,27,female
pia,20,female
ard,27,male
janos,29,male
juan,40,male
pedro,22,male
carla,34,female
jose,30,male
anne,25,female
rey,33,male
joyce,27,female
pia,20,female
ard,27,male
janos,29,male
juan,40,male
pedro,22,male
carla,34,female
jose,30,male
anne,25,female
rey,33,male
joyce,27,female
pia,20,female
ard,27,male
janos,29,male
juan,40,male
pedro,22,male
carla,34,female
jose,30,male
anne,25,female
rey,33,male
joyce,27,female
pia,20,female
ard,27,male
樣本輸出:
[
{
"name": "janos",
"age": "29",
"gender": "male"
},
{
"name": "juan",
"age": "40",
"gender": "male"
},
{
"name": "pedro",
"age": "22",
"gender": "male"
},
{
"name": "carla",
"age": "34",
"gender": "female"
},
{
"name": "jose",
"age": "30",
"gender": "male"
},
{
"name": "anne",
"age": "25",
"gender": "female"
},
{
"name": "rey",
"age": "33",
"gender": "male"
},
{
"name": "joyce",
"age": "27",
"gender": "female"
},
{
"name": "pia",
"age": "20",
"gender": "female"
},
{
"name": "ard",
"age": "27",
"gender": "male"
},
{
"name": "janos",
"age": "29",
"gender": "male"
},
{
"name": "juan",
"age": "40",
"gender": "male"
},
{
"name": "pedro",
"age": "22",
"gender": "male"
},
{
"name": "carla",
"age": "34",
"gender": "female"
},
{
"name": "jose",
"age": "30",
"gender": "male"
},
{
"name": "anne",
"age": "25",
"gender": "female"
},
{
"name": "rey",
"age": "33",
"gender": "male"
},
{
"name": "joyce",
"age": "27",
"gender": "female"
},
{
"name": "pia",
"age": "20",
"gender": "female"
},
{
"name": "ard",
"age": "27",
"gender": "male"
},
{
"name": "janos",
"age": "29",
"gender": "male"
},
{
"name": "juan",
"age": "40",
"gender": "male"
},
{
"name": "pedro",
"age": "22",
"gender": "male"
},
{
"name": "carla",
"age": "34",
"gender": "female"
},
{
"name": "jose",
"age": "30",
"gender": "male"
},
{
"name": "anne",
"age": "25",
"gender": "female"
},
{
"name": "rey",
"age": "33",
"gender": "male"
},
{
"name": "joyce",
"age": "27",
"gender": "female"
},
{
"name": "pia",
"age": "20",
"gender": "female"
},
{
"name": "ard",
"age": "27",
"gender": "male"
},
{
"name": "janos",
"age": "29",
"gender": "male"
},
{
"name": "juan",
"age": "40",
"gender": "male"
},
{
"name": "pedro",
"age": "22",
"gender": "male"
},
{
"name": "carla",
"age": "34",
"gender": "female"
},
{
"name": "jose",
"age": "30",
"gender": "male"
},
{
"name": "anne",
"age": "25",
"gender": "female"
},
{
"name": "rey",
"age": "33",
"gender": "male"
},
{
"name": "joyce",
"age": "27",
"gender": "female"
},
{
"name": "pia",
"age": "20",
"gender": "female"
},
{
"name": "ard",
"age": "27",
"gender": "male"
}
]
希望這有助於。
您能否提供流程的XML以獲取更多上下文? – CountD
你選擇的目的是什麼? –