我想彙總一個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