Notifications
Announcements
Hi how can i summarize all JSON values togetehr?
BODY:
{ "Pallets":
{ "Gross_Weight": "575 kg",
"Net_Weight": "" },
{ "Gross_Weight": "720 kg",
{ "Gross_Weight": "50 kg",
"Net_Weight": "" }}
Hi @Zohaib1999
Pls let me know the excepted result from the output of compose action.
I want to sum all values together in one compose "TotalGrossWeight" and a another one "TotalNetWeight". Since there could be more then one i need prob a 'for each' condition. But i failing doing that so i asked here for support.
You can use xml & xpath functions to get the sum. Here is a sample flow.
I have stored input array in a compose action:
{ "Pallets":[{ "Gross_Weight": "575 kg","Net_Weight": ""},{ "Gross_Weight": "720 kg","Net_Weight": "" },{ "Gross_Weight": "50 kg","Net_Weight": "" }]}
Add another compose action. We will be using expression to get the sum of all nodes using xml & xpath. Expression needs to be added in the expression box as shown below:
concat(xpath(xml(json(replace(concat('{"root":',outputs('Compose'),'}'),' kg',''))),'sum(//Gross_Weight)'),' kg')
Output:
If this helps & solves your problem, please remember to give a 👍 and accept my solution as it will help others in the future.
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
In our never-ending quest to improve we are simplifying the forum hierarchy…
We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Michael E. Gernaey 538 Super User 2025 Season 2
Tomac 405 Moderator
abm abm 252 Most Valuable Professional