Skip to content

|=.? returns empty #2140

@vintnes

Description

@vintnes

Thank you for this life-changing language. I regret that my first correspondence is a complaint.

Try-catch returns empty following filter assignment.

Input

 jq -nc '{foo: "bar"} | .foo |= .?'  

Expected output

 {"foo":"bar"}

Actual output

{}

Furthermore, // is unable to catch the result:

$ jq -nc '{foo: "bar"} | .foo |= ( .? // "baz" )'
{}

Environment (please complete the following information):

  • Debian Stretch, jq 1.5
  • jqplay, jq 1.6

This is an extremely minimized example; I'm actually trying to process incoming strings which may or may not contain valid JSON, as in .value |= (fromjson? // .). I catch some undocumented error formatting when I try this:

$ jq -nc '{value: "[]"} | .value |= try fromjson catch .'
{"value":{"__jq":0}}

Thanks again for your efforts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions