jmespath / jmespath.py

JMESPath is a query language for JSON.
http://jmespath.org
MIT License
2.19k stars 181 forks source link

Add a group_by function #153

Open ChenXiaoTemp opened 6 years ago

ChenXiaoTemp commented 6 years ago

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.

innovate-invent commented 5 years ago

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

springcomp commented 2 years ago

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