Jq: Using `try` or `?` breaks the update operator (`|=`)

Created on 25 Jan 2018  路  3Comments  路  Source: stedolan/jq

Using try or ? on the RHS of the |= operator removes the path being updated, even if the update expression works correctly without any error handling.

I'm using jq-1.6rc1-1-g61edf3f

Example program:

{"number":"1234"}|(.number|=23),(.number|=23?)

Expected output:

{
  "number": 23
}
{
  "number": 23
}

Actual output:

{
  "number": 23
}
{}

jq 1.5 behaves as expected.

bug

Most helpful comment

This issue is still present in stable release jq-1.6.

I've tried following test cases:
{"price": "$23,000"} | .price |= (try 2 catch null)
{"price": null} # expected 2

The output is correct If update operator or try-catch is removed:
{"price": "$23,000"} | . + {price: (try 2 catch null)}
{ "price": 2}
{"price": "$23,000"} | .price |= 2
{ "price": 2}

Jq-1.5 works as expected. Is there any update on this issue? Is it related to the documented change of behavior of update operator?

All 3 comments

Thanks for the report.

This issue is still present in stable release jq-1.6.

I've tried following test cases:
{"price": "$23,000"} | .price |= (try 2 catch null)
{"price": null} # expected 2

The output is correct If update operator or try-catch is removed:
{"price": "$23,000"} | . + {price: (try 2 catch null)}
{ "price": 2}
{"price": "$23,000"} | .price |= 2
{ "price": 2}

Jq-1.5 works as expected. Is there any update on this issue? Is it related to the documented change of behavior of update operator?

Fixed by @wtlangford with e74eab8.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

benjamin-bin-shen picture benjamin-bin-shen  路  3Comments

rokka-n picture rokka-n  路  4Comments

ghost picture ghost  路  4Comments

sloanlance picture sloanlance  路  3Comments

LoganBarnett picture LoganBarnett  路  3Comments