我有两个Json有效负载.我想将它们合并到单个Json对象中 [英] I have two Json payload. I want to merge them in a single Json object
问题描述
我有两个有效负载,想将它们合并到单个JSON对象中(流连接).人们建议在少数地方使用AttributesToJSON,但是由于其中一个JSON没有固定的属性集,我想那是不可能的.
I have two payloads and want to merge them into single JSON object (streaming join). At few places people are suggesting to use AttributesToJSON, but as one of the JSON does not have fix set of attributes I guess that would not be possible.
第一个有效载荷是
{
"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"
}
]
}
推荐答案
容易!只需使用MergeContent
并设置以下配置即可:
Easy! Just use MergeContent
and set the following configuration:
Merge Format: Binary Concatenation
Minimum Number of Entries: 2
Delimiter Strategy: Text
Header: [
Footer: ]
Demarcator: ,
(您可以使用MergeRecord
,但是至少对我来说这有点麻烦).
(You could use MergeRecord
but it is a little buggy for me at least).
然后转移到JoltTrasnformJSON
,并将Jolt Transformation DSL
设置为Shift
,将Jolt Specification
设置为:
Then transfer to JoltTrasnformJSON
and set Jolt Transformation DSL
to Shift
and Jolt Specification
to:
{
"*": {
"*": "&"
}
}
这应该可以完成:)
这篇关于我有两个Json有效负载.我想将它们合并到单个Json对象中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!