如何解决Excel到Dataweave 2.0中的Json映射
我有一张Excel工作表。我希望将其映射到json配置文件。
我想转换成json
[
{
"Scope" : {
"Content owner" : "","Language" : "","Territory" : ""
},"Title" : {
"Content ID" : "","Billing ID" : "","IMDB" : "","Name" : "","Episode Number" : "","Episode Sequence" : "","Container Position" : "","Run Length" : "","Work Type" : "","Short Synopsis" : "","Long Synopsis" : "","Original Language" : "","Rating Set1" : "","Rating Set2" : "","Rating Set3" : "","Rating Set4" : "","Rating Set5" : "".....
像这样...该行将是主要对象,下一行将是第二个对象...,然后是实际数据。我尝试过,但无法动态获取。我使用了一些静态索引值,但对结果不满意。
感谢您的帮助
谢谢!
解决方法
Dataweave无法以动态方式100%解决它。您可以尝试使用以下表达式:
%dw 2.0
output application/json
//endIndex: use -1 to include all remaining fields
fun addFields(item,startColIdx,endColIdx) =
(item pluck (value,key,index) -> (key): value) filter ($$ >= startColIdx and (endColIdx == -1 or $$ <= endColIdx)) reduce ($$ ++ $)
---
payload map(item,index) -> {
'Scope': addFields(item,2),'Title': addFields(item,3,-1)
}
您可以使用上述表达式的另一个版本,但可以考虑起始列索引和列数(而不是考虑起始列索引和结束列索引)(从索引0开始获取3列,而不是从索引索引0到获取列)列索引2):
%dw 2.0
output application/json
//endIndex: use -1 to include all remaining columns
fun addFields(item,colCnt) =
(item pluck (value,index) -> (key): value) filter ($$ >= startColIdx and (colCnt == -1 or $$ < startColIdx + colCnt)) reduce ($$ ++ $)
---
payload map(item,3),-1)
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。