I like JMESPath, but it has some serious limitations which prevent it from being as general purpose as jq.
JMESPath limitations:
- No simple if/else, but it is possible using a hack, documented below.
- The to_number function doesn't support boolean values, but it is possible using a hack, documented below.
- can't reference parents when doing iteration. Why? All options for iteration, [* ] and map, all use the iterated item as the context for any expression. There's no opportunity to get any other values in. May be possible for a fixed set of lengths. Something akin to the following (except there is no syntax for switching or if statements):
switch (length):
case 1: [expression[0]]
case 2: [expression[1], expression[1]]
case 3: [expression[0], expression[1], expression[2]]
...
- Key name can't come from an expression. Why? The ABNF for constructing key-value pairs is given as: keyval-expr = identifier ":" expression. The key is an identifier, which gives no possibility for making it an expression. No functions modify keys in such a way as to allow using an expression as a key.)
- No basic math operations, add, multiply, divide, mod, etc. Why? Nobody added those operators/functions.
- There's a join, but no split.
- No array indexing based on expression. Why? Indexing is done based on a number or a slice expression, which also doesn't support expressions. Here's the ABNF:
JMESPath limitations:
- No simple if/else, but it is possible using a hack, documented below.
- The to_number function doesn't support boolean values, but it is possible using a hack, documented below.
- can't reference parents when doing iteration. Why? All options for iteration, [* ] and map, all use the iterated item as the context for any expression. There's no opportunity to get any other values in. May be possible for a fixed set of lengths. Something akin to the following (except there is no syntax for switching or if statements):
- Key name can't come from an expression. Why? The ABNF for constructing key-value pairs is given as: keyval-expr = identifier ":" expression. The key is an identifier, which gives no possibility for making it an expression. No functions modify keys in such a way as to allow using an expression as a key.)- No basic math operations, add, multiply, divide, mod, etc. Why? Nobody added those operators/functions.
- There's a join, but no split.
- No array indexing based on expression. Why? Indexing is done based on a number or a slice expression, which also doesn't support expressions. Here's the ABNF:
- No ability to group_by an expression.- No ability to get the index of an element in a list
Hacks:
Convert true/false to number:
If/else:Option 1)
Option 2)