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"
}
}
]
}
나는 XSL로 XML에 수행하는 방법을 알고있다. 그러나 나는 카멜 자바에서 이것을하는 법을 모른다. .. 당신에게 생각 나니?
jsonPath를 살펴보십시오. –
이렇게하면 Talend에서 다음과 같이 할 수 있습니다. json을 읽고 추가하려는 필드에 tAggregate를 사용하여 나중에 JSON을 인쇄하십시오. – tobi6