我有两个有效负载,想将它们合并到单个JSON对象中(流连接)。人们建议在少数地方使用AttributesToJSON,但是由于其中一个JSON没有固定的属性集,我想那是不可能的。
第一个有效载荷是
{
"title":"API-Actions Documentation",
"title_link":"https://api.slack.com/",
"author_name":"name",
"author_link":"http://flickr.com/bobby/",
"author_icon":"http://flickr.com/icons/bobby.jpg",
"text":"Optional",
"image_url":"http://my-website.com/path/to/image.jpg",
"thumb_url":"http://example.com/path/to/thumb.png",
"footer":null,
"pretext":"@name",
"color":"#7CD197"
}
第二个是
{
"fields":[
{
"title":"Priority",
"value":"low",
"short":"true"
},
{
"title":"Priority",
"value":"medium",
"short":"true"
},
{
"title":"Priority",
"value":"high",
"short":"true"
},
{
"title":"Priority",
"value":"blocker",
"short":"true"
}
]
}
我希望输出为
{
"title":"API-Actions Documentation",
"title_link":"https://api.slack.com/",
"author_name":"name",
"author_link":"http://flickr.com/bobby/",
"author_icon":"http://flickr.com/icons/bobby.jpg",
"text":"Optional",
"image_url":"http://my-website.com/path/to/image.jpg",
"thumb_url":"http://example.com/path/to/thumb.png",
"footer":null,
"pretext":"@name",
"color":"#7CD197",
"fields":[
{
"title":"Priority",
"value":"low",
"short":"true"
},
{
"title":"Priority",
"value":"medium",
"short":"true"
},
{
"title":"Priority",
"value":"high",
"short":"true"
},
{
"title":"Priority",
"value":"blocker",
"short":"true"
}
]
}
答案 0 :(得分:2)
容易!只需使用MergeContent
并设置以下配置即可:
Merge Format: Binary Concatenation
Minimum Number of Entries: 2
Delimiter Strategy: Text
Header: [
Footer: ]
Demarcator: ,
(您可以使用MergeRecord
,但至少对我来说是个小问题)。
然后转移到JoltTrasnformJSON
,并将Jolt Transformation DSL
设置为Shift
,将Jolt Specification
设置为:
{
"*": {
"*": "&"
}
}
这应该可以完成:)