jmespath.py icon indicating copy to clipboard operation
jmespath.py copied to clipboard

Add a group_by function

Open ChenXiaoTemp opened this issue 8 years ago • 2 comments

Use case:

Given

[ {"type":"large","ip":"10.0.0.1"}, {"type":"large","ip":"10.0.0.2"}, {"type":"small","ip":"10.0.0.3"} ] I'd like to create:

{ "large": [{"type":"large","ip":"10.0.0.1"},{"type":"large","ip":"10.0.0.2"}], "small":[{"type":"small","ip":"10.0.0.3"}] }

Is there any query expression to do it?

Thanks very much.

ChenXiaoTemp avatar Nov 10 '17 10:11 ChenXiaoTemp

if you know the groups ahead of time try: {large: [? type == `large` ], small: [? type == `small` ]

innovate-invent avatar May 04 '19 21:05 innovate-invent

The group_by() function is currently being proposed for inclusion in the next version of JMESPath Community.

springcomp avatar Aug 07 '22 08:08 springcomp