-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Labels
Description
There's currently no way to assert if the structure of an object exactly matches a pattern, even with the alternate destructuring ?//
:
$ jq -r '. as [$foo] | $foo' <<<'["foo"]'
foo
$ jq -r '. as [$foo] | $foo' <<<'["foo", "bar"]'
foo
$ jq -r '. as [$foo,$bar] ?// [$bar] | $bar' <<<'["foo"]'
null
It would be helpful if there's a destructuring operator that will throw an error if there are no exact matches. Perhaps it could look something like:
$ jq -r '. is [$foo] | $foo' <<<'["foo", "bar"]'
jq: error (at <stdin>:1): Cannot destructure array with pattern [$foo]
$ jq -r '. is [$foo,$bar] ?// [$bar] | $bar' <<<'["foo"]'
foo
$ jq -r '. is [$foo,$bar] ?// [$bar] | $bar' <<<'["foo","bar","baz"]'
jq: error (at <stdin>:1): Cannot destructure array with pattern [$bar]