我想汇总一个Json文件。 我使用Talend来做到这一点,所以我必须在java中进行这种转换。 这是一个订单文件。如何聚合json文件?
{
"order" : [{
"order_line" : {
"name" : "Pains au lait aux pépites de chocolat, 350 g",
"unit_price" : 2.39,
"ean" : "3256540011465",
"price" : 4.78,
"quantity" : 2,
"date" : "-0001-11-30T00:00:00+0009",
"ref" : "23806"
}
}, {
"order_line" : {
"name" : "Eau de montagne, 6 x 1.5 L",
"unit_price" : 1.99,
"ean" : "3596710383931",
"price" : 1.99,
"quantity" : 1,
"date" : "-0001-11-30T00:00:00+0009",
"ref" : "117797"
}
}, {
"order_line" : {
"name" : "Eau de montagne, 6 x 1.5 L",
"unit_price" : 1.99,
"ean" : "3596710383931",
"price" : 1.99,
"quantity" : 1,
"date" : "-0001-11-30T00:00:00+0009",
"ref" : "117797"
}
}, {
"order_line" : {
"name" : "Pains au lait aux pépites de chocolat, 350 g",
"unit_price" : 2.39,
"ean" : "3256540011465",
"price" : 4.78,
"quantity" : 2,
"date" : "-0001-11-30T00:00:00+0009",
"ref" : "23806"
}
}
]
}
我的文件包含订单中的项目,但一式两份。
如果标签“name”,“ean”,“ref”,“unit_price”相同,我想在相同的“order_line”中添加数量并删除“order_line”一式两份。
而且我想这一点:
{
"order" : [{
"order_line" : {
"name" : "Pains au lait aux pépites de chocolat, 350 g",
"unit_price" : 2.39,
"ean" : "3256540011465",
"price" : 4.78,
"quantity" : 4,
"date" : "-0001-11-30T00:00:00+0009",
"ref" : "23806"
}
}, {
"order_line" : {
"name" : "Eau de montagne, 6 x 1.5 L",
"unit_price" : 1.99,
"ean" : "3596710383931",
"price" : 1.99,
"quantity" : 2,
"date" : "-0001-11-30T00:00:00+0009",
"ref_fo" : "117797"
}
}
]
}
我知道如何在XML做XSL。 但我不知道如何在Camel Java中做到这一点...你有什么想法吗?
看看jsonPath。 –
你可以像这样用Talend实现这个目标:阅读json,在你想添加的字段上使用tAggregate,然后打印出JSON。 – tobi6