我有两个 Json 有效负载.我想将它们合并到一个 Json 对象中 [英] I have two Json payload. I want to merge them in a single Json object

查看:28
本文介绍了我有两个 Json 有效负载.我想将它们合并到一个 Json 对象中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个有效负载,想将它们合并为单个 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设置为ShiftJolt Specification:

Then transfer to JoltTrasnformJSON and set Jolt Transformation DSL to Shift and Jolt Specification to:

{
    "*": {
      "*": "&"
    }
}

这应该可以完成工作:)

This should do the job :)

这篇关于我有两个 Json 有效负载.我想将它们合并到一个 Json 对象中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆