Skip to content

Commit

Permalink
Document new assert builtin
Browse files Browse the repository at this point in the history
  • Loading branch information
mrwilson committed Aug 24, 2023
1 parent a7941d4 commit da0a6a1
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
23 changes: 23 additions & 0 deletions docs/content/manual/manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1974,6 +1974,29 @@ sections:
output:
- '[{"a":{"b":2}}]'

- title: "`assert(test; $message)`"
body: |
The `assert(test; $message)` function applies the test to the
input entity. If the test passes (returns true) then the output
is the original input. If the test fails then JQ throws an error
containing the message passed in.
This can be used to short-circuit pipelines in scripts such as when
you want to stop if there is a missing key, or the input is an empty
array.
examples:
- program: 'assert(length > 0; "must not be empty")'
input: '[1,2,3,4]'
output:
- '[1,2,3,4]'

- program: 'assert(values | add >= 10 ; "values must total at least 10")'
input: '{"a": 1, "b": 2 }'
output:
- '"assertion error: values must total at least 10"'

- title: "`$JQ_BUILD_CONFIGURATION`"
body: |
Expand Down
22 changes: 22 additions & 0 deletions jq.1.prebuilt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions tests/man.test

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit da0a6a1

Please sign in to comment.