如何使用 Jolt 按两个键聚合 JSON 数据?
How do I aggregate JSON data using Jolt by two keys?
如果我有一个 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",
}]
}
"2015-02-18":{
“clothes”:[{
"date": "2015-02-18",
"buyer": "Alyssa",
"category": "clothes",
"quantity": "13.0",
}],
"food":[{
"date": "2015-02-18",
"buyer": "Lisa",
"category": "food",
"quantity": "2.0"
},
{
"date": "2015-02-18",
"buyer": "Brian",
"category": "food",
"quantity": "11.0",
}]
}
}
出人意料的简单。
规格
[
{
"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)[]"
}
}
}
]
如果我有一个 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",
}]
}
"2015-02-18":{
“clothes”:[{
"date": "2015-02-18",
"buyer": "Alyssa",
"category": "clothes",
"quantity": "13.0",
}],
"food":[{
"date": "2015-02-18",
"buyer": "Lisa",
"category": "food",
"quantity": "2.0"
},
{
"date": "2015-02-18",
"buyer": "Brian",
"category": "food",
"quantity": "11.0",
}]
}
}
出人意料的简单。
规格
[
{
"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)[]"
}
}
}
]