summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpkoppstein <pkoppstein@gmail.com>2023-07-02 23:35:41 -0400
committerGitHub <noreply@github.com>2023-07-03 12:35:41 +0900
commit3c76a5b3f3b9ffa874c75939f140a1aad81da9b5 (patch)
tree39a9a64b99192fab1f2aa81b34ec02523d0faa62
parent4b5fcb936f294ec90952414eb0c3aa800dbc101d (diff)
manual.yml: fix references to javascript, and clarify semantics of == (#2645)
remove inaccurate and confusing references to javascript; clarify semantics of ==
-rw-r--r--docs/content/manual/manual.yml24
-rw-r--r--tests/man.test8
2 files changed, 24 insertions, 8 deletions
diff --git a/docs/content/manual/manual.yml b/docs/content/manual/manual.yml
index db28677c..f9bdb102 100644
--- a/docs/content/manual/manual.yml
+++ b/docs/content/manual/manual.yml
@@ -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
diff --git a/tests/man.test b/tests/man.test
index b535362f..9815878d 100644
--- a/tests/man.test
+++ b/tests/man.test
@@ -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