如何使用DataWeave与JSON中的字符串的数据实现预期输出
如何使用Mulesoft的DataWeave语言将输入中的JSON数据转换为XML,如输出所示。
输入
{
"sponsors":[{
"SP1": "John Smith",
"NINO": "SC105012B",
"INCOME1": 10000,
"INCOME2":12000,
"DEPENDENTDETAILS": "No, FirstName, LastName, DateOfBirth, EduStatus, Income; 1, John, Smith, 12/12/84, studying at college or university, yes; 2, williams, Smith, 20/06/84, studying at college or university, No;"
}]
}
预期输出
<sponsors>
<sp1>john smith</sp1>
<nino>sc15012b</nino>
<income1>10000</income1>
<income2>12000</income2>
<dependentdetails>
<no>1</no>
<firstname>john</firstname>
<lastname>smith</lastname>
<dateOfBirth>12/12/84</dateOfBirth>
<EduStatus>studying in college or university<EduStatus/>
<Income>yes</Income>
<no>2</no>
<firstname>williams</firstname>
<lastname>smith</lastname>
<dateOfBirth>20/06/84</dateOfBirth>
<EduStatus>studying in college or university<EduStatus/>
<Income>No</Income>
</dependentdetails>
</sponsors>
How to transform json data as shown in input into XML as shown in output using MuleSoft's DataWeave language.
Input
{
"sponsors":[{
"SP1": "John Smith",
"NINO": "SC105012B",
"INCOME1": 10000,
"INCOME2":12000,
"DEPENDENTDETAILS": "No, FirstName, LastName, DateOfBirth, EduStatus, Income; 1, John, Smith, 12/12/84, studying at college or university, yes; 2, williams, Smith, 20/06/84, studying at college or university, No;"
}]
}
Expected Output
<sponsors>
<sp1>john smith</sp1>
<nino>sc15012b</nino>
<income1>10000</income1>
<income2>12000</income2>
<dependentdetails>
<no>1</no>
<firstname>john</firstname>
<lastname>smith</lastname>
<dateOfBirth>12/12/84</dateOfBirth>
<EduStatus>studying in college or university<EduStatus/>
<Income>yes</Income>
<no>2</no>
<firstname>williams</firstname>
<lastname>smith</lastname>
<dateOfBirth>20/06/84</dateOfBirth>
<EduStatus>studying in college or university<EduStatus/>
<Income>No</Income>
</dependentdetails>
</sponsors>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
DepentEntDetails似乎是
;
分开的标题和记录,每个字段由,
隔开。一旦我们按了每个字符分开,我们就可以获取一个字段名称列表和每个记录的值列表,我们可以轻松操纵这些记录。DEPENDENTDETAILS seems to be a string of headers and records separated by
;
and each field separated by,
. Once we split by each of those characters we can get a list of field names and a list of values for each records that we can manipulate easily.您还有一个可以尝试的选择
There is one more option that you can try