Skip to content

Commit 7f27e8b

Browse files
committed
docs: describe using map around objects in the gotchas section
1 parent 3162e6e commit 7f27e8b

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,14 @@ $ cat users.json | jsonquery 'sort(.age)' > output.json
613613

614614
The JSON Query language has some gotchas. What can be confusing at first is to understand how data is piped through the query. A traditional function call is for example `max(myValues)`, so you may expect to have to write this in JSON Query like `["max", "myValues"]`. However, JSON Query has a functional approach where we create a pipeline like: `data -> max -> result`. So, you will have to write a pipe which first gets this property and next calls the function max: `.myValues | max()`.
615615

616+
Another gotcha is that unlike some other query languages, you need to use the `map` function to pick some properties out of an array _for every item_ in the array. When you're just picking a few fields without renaming them, you can use the function `pick` too, which is more concise.
617+
618+
```
619+
.friends | { firstName: .name, age: .age } WRONG
620+
.friends | map({ firstName: .name, age: .age }) RIGHT
621+
.friends | pick(.name, .age) RIGHT
622+
```
623+
616624
## Development
617625

618626
To develop, check out the repo, install dependencies once, and then use the following scripts:

0 commit comments

Comments
 (0)