group_by()
function
#96
-
group_by function
AbstractThis JEP introduces a new Specificationgroup_by
Given an array of objects Objects that do not match the group criteria are grouped under a key named ExamplesGiven the following input JSON document: {
"array": [
{ "a": 1, "b": true },
{ "a": 1, "b": false },
{ "a": 2 },
{ "a": null, "b": false }
]
} Here are several examples:
Alternatives consideredConcerns are raised against introducing too many functions into JMESPath where clever syntax and existing functions would be possible instead. History |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
@glenveegee I took the liberty to publish an initial draft of a JEP based on your suggestion. Please feel free to provide feedback. The main difference based on your suggestion is that the result should be a valid JSON object, whose keys are string types. |
Beta Was this translation helpful? Give feedback.
-
I’m not sure we should keep the non matching items and consider whether to drop them outright. The result of the grouping in the first motivating example would then be: {
"1": [{"a": 1, "b": true}, {"a": 1, "b": false}],
"2": [{"a": 2}]
} Whereas the result from the second example would be: {
"true": [{"a": 1, "b": true}],
"false": [{"a": 1, "b": false}, {"a": null, "b": false}]
} |
Beta Was this translation helpful? Give feedback.
-
I think we should only restrict the The signature becomes:
The first and second motivating examples would become (although they would not be relevant anymore in the spec):
|
Beta Was this translation helpful? Give feedback.
I think we should only restrict the
group_by()
function to grouping on string types.That is, the
expression-type
should evaluate to a string.The signature becomes:
The first and second motivating examples would become (although they would not be relevant anymore in the spec):
group_by(array, &to_string(a))
group_by(array, &to_string(b))