1
0
mirror of https://github.com/stedolan/jq.git synced 2024-05-11 05:55:39 +00:00

manual.yml: fix references to javascript, and clarify semantics of == (#2645)

remove inaccurate and confusing references to javascript; clarify semantics of ==
This commit is contained in:
pkoppstein
2023-07-02 23:35:41 -04:00
committed by GitHub
parent 4b5fcb936f
commit 3c76a5b3f3
2 changed files with 24 additions and 8 deletions

View File

@@ -559,7 +559,7 @@ sections:
hashes with only string keys), and "null".
Booleans, null, strings and numbers are written the same way as
in javascript. Just like everything else in jq, these simple
in JSON. Just like everything else in jq, these simple
values take an input and produce an output - `42` is a valid jq
expression that takes an input, ignores it, and returns 42
instead.
@@ -2116,16 +2116,24 @@ sections:
- title: "`==`, `!=`"
body: |
The expression 'a == b' will produce 'true' if the result of a and b
are equal (that is, if they represent equivalent JSON documents) and
The expression 'a == b' will produce 'true' if the results of evaluating
a and b are equal (that is, if they represent equivalent JSON values) and
'false' otherwise. In particular, strings are never considered equal
to numbers. If you're coming from JavaScript, jq's == is like
JavaScript's === - considering values equal only when they have the
same type as well as the same value.
to numbers. In checking for the equality of JSON objects, the ordering of keys
is irrelevant. If you're coming from JavaScript, please note that jq's `==` is like
JavaScript's `===`, the "strict equality" operator.
!= is "not equal", and 'a != b' returns the opposite value of 'a == b'
examples:
- program: '. == false'
input: 'null'
output: ['false']
- program: '. == {"b": {"d": (4 + 1e-20), "c": 3}, "a":1}'
input: '{"a":1, "b": {"c": 3, "d": 4}}'
output: ['true']
- program: '.[] == 1'
input: '[1, 1.0, "1", "banana"]'
output: ['true', 'true', 'false', 'false']
@@ -2145,8 +2153,8 @@ sections:
"truthiness" than is found in JavaScript or Python, but it
means that you'll sometimes have to be more explicit about
the condition you want. You can't test whether, e.g. a
string is empty using `if .name then A else B end`, you'll
need something more like `if .name == "" then A else B end` instead.
string is empty using `if .name then A else B end`; you'll
need something like `if .name == "" then A else B end` instead.
If the condition `A` produces multiple results, then `B` is evaluated
once for each result that is not false or null, and `C` is evaluated

View File

@@ -668,6 +668,14 @@ strptime("%Y-%m-%dT%H:%M:%SZ")|mktime
"2015-03-05T23:51:47Z"
1425599507
. == false
null
false
. == {"b": {"d": (4 + 1e-20), "c": 3}, "a":1}
{"a":1, "b": {"c": 3, "d": 4}}
true
.[] == 1
[1, 1.0, "1", "banana"]
true