@ivan.lyagin Need help with getting sum of objects based on some condition.
Example below json:
String json = "{ name: \"John doe\", "
+ "age: 18 ,"
+ "values: [ "
+ "{ category:“A”, value:5 },"
+ "{ category:“A”, value:5 },"
+ "{ category:“A”, value:5 },"
+ "{ category:“B”, value:1 },"
+ "{ category:“B”, value:1 },"
+ "{ category:“B”, value:1 },"
+ "{ category:“B”, value:1 },"
+ "{ category:“C”, value:2 },"
+ "{ category:“C”, value:2 },"
+ "{ category:“C”, value:2 },"
+ "{ category:“C”, value:2 }"
+ " ] ,"
+ "values2: []"
+ "}";
I need to get sum of category A than get sum of B and so on…
In this case the number has the same key (value).
Something like the below:
A sum: <<[where(e=> e.category == "A").sum(e=> e.value)]: "0.00">>
B sum: <<[where(e=> e.category == "B").sum(e=> e.value)]: "0.00">>
C sum: <<[where(e=> e.category == "B").sum(e=> e.value)]: "0.00">>
This is not working for us.
Before we achieved the sum but we had different value keys, like value1, value2, value3 but we have the case of value for all.
Thanks for your help.