Object Manipulation Functions #47
-
We need a mechanism for building objects with an unknown number of keys. This has already been extensively discussed and this discussion is to summarise, preparing to create a JEP. jmespath/jmespath.py#105 The proposed functions are:
examples: an alternative to an alternative to an alternative to I think with these alternatives, we need to discuss how strictly we want to adhere to the "one way of doing something" guideline. Where do we draw the line between a wiki of reusable patterns and adding functions to simplify? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 19 replies
-
The more I think about this, the more I am worried we are adding functions that should actually be syntax. This is most apparent when considering alternatively we could look at adding a spread operator to multiselect list and hash: We also have two different ways of applying the If we go this route then the alternatives would be: or with the reduce operation or with the spread operator: or with the set union operator: |
Beta Was this translation helpful? Give feedback.
-
Object Manipulation Functions
AbstractAs a JSON querying language, JMESPath has long needed some functions to manipulate JSON objects. This JEP introduces built-in functions to extract a list of key/value pairs from a JSON object and conversely converting an array of key/value pairs to a JSON object. Specificationitems
Returns a an array of key value pairs for the provided object Note that because JSON hashes are inheritently unordered, the key value pairs of the provided object For example, given the input: {"a": "first", "b": "second", "c": "third"} The expression
If you would like a specific order, consider using the Examples
from_items
Returns an object from the provided array of key value pairs. This function is the inverse of the Examples
zip
Accepts one or more arrays as arguments and returns an array of arrays in which the i-th array contains the i-th element from each of the argument arrays. The returned array is truncated to the length of the shortest argument array. Examples
Compliance testsA new HistoryN/A |
Beta Was this translation helpful? Give feedback.
-
Should |
Beta Was this translation helpful? Give feedback.
Object Manipulation Functions
Abstract
As a JSON querying language, JMESPath has long needed some functions to manipulate JSON objects.
This JEP introduces built-in functions to extract a list of key/value pairs from a JSON object and conversely converting an array of key/value pairs to a JSON object.
Specification
items
Returns a an array of key value pairs for the provided object
$obj
. Each pair is a 2-item array with the first item being the key and the second item being the value. This function is the inverse of thefrom_items()
…