为了账号安全,请及时绑定邮箱和手机立即绑定

如何通过两个键使用 Jolt 聚合 JSON 数据?

如何通过两个键使用 Jolt 聚合 JSON 数据?

12345678_0001 2021-08-04 17:02:06
如果我有一个 JSON 对象列表的输入。我如何按日期在Java 中嵌套数据,然后按日期按降序排列类别?输入:    { "data":[{      "date": "2015-02-26",      "buyer": "Ryan",      "category": "clothes",      "quantity":"10.0"    },    {      "date": "2015-02-18",      "buyer": "Lisa",      "category": "food",      "quantity": "2.0"    },        {      "date": "2015-02-18",      "buyer": "Brian",      "category": "food",      "quantity": "11.0",    },    {      "date": "2015-02-26",      "buyer": "Jim",      "category": "clothes",      "quantity": "20.0",    },    {      "date": "2015-02-26",      "buyer": "Tom",      "category": "food",      "quantity": "40.0",    },    {      "date": "2015-02-18",      "buyer": "Alyssa",      "category": "clothes",      "quantity": "13.0",    }]}您可以在下面的输出中看到,我首先尝试按日期对数据进行分组,然后在该日期内按类别对对象进行分组。期望输出:{    "2015-02-26”:{                    “clothes”:[{                                "date": "2015-02-26",                                "buyer": "Ryan",                                "category": "clothes",                                "quantity":"10.0"                                },                                {                                    "date": "2015-02-26",                                    "buyer": "Jim",                                    "category": "clothes",                                    "quantity": "20.0",                                }],                    "food":[{                                  "date": "2015-02-26",                                  "buyer": "Tom",                                  "category": "food",                                  "quantity": "40.0",                            }]                }
查看完整描述

1 回答

?
慕斯709654

TA贡献1840条经验 获得超5个赞

出人意料的轻松。


规格


[

  {

    "operation": "shift",

    "spec": {

      "data": {

        // Ex. send the first data item to 

        //    2015-02-26.clothes[] 

        //    where we want clothes to always be an array 

        //    even if it only got one value assigned to it.

        "*": "@(0,date).@(0,category)[]"

      }

    }

  }

]


查看完整回答
反对 回复 2021-08-04
  • 1 回答
  • 0 关注
  • 158 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信