Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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:

  bracket-specifier = "[" (number / "* " / slice-expression) "]" / "[]"
- 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:

  boolean_expression && `1` || `0`
If/else:

Option 1)

  [{q:CONDITIONAL_EXPRESSION, v:IF_RESULT_EXPRESSION},{q:!COND_EXPRESSION,v:ELSE_RESULT_EXPRESSION}][?q]|[0].v
Option 2)

  {"if":CONDITIONAL_EXPRESSION, "ctx":@} | [{q:if ,v:ctx.IF_EXPRESSION},{q:!if,v:ctx.ELSE_EXPRESSION}][?q]|[0].v



Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: