Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation Request: Include additional examples in the "Update assignment: |=" section #3032

Open
DanKaplanSES opened this issue Feb 4, 2024 · 2 comments
Labels

Comments

@DanKaplanSES
Copy link

DanKaplanSES commented Feb 4, 2024

I'm referring to this section: https://jqlang.github.io/jq/manual/#update-assignment

For context, I was trying to figure out how to update a deeply nested portion of a json document and print the original input with those modifications (a la sed -e 's/few/many/g'). Through trial and error, I discovered |= was needed for this, but it was difficult for me to learn that from the example (and the documentation, but that's tangential to this issue):

Filter: (..|select(type=="boolean")) |= if . then 1 else 0 end
Input: [true,false,[5,true,[true,[false]],false]]
Output: [1,0,[5,1,[1,[0]],0]]

This example includes .., select, equality, and if/else. Each are a lesson in their own right but irrelevant to learning |=. To be clear, I'm not saying this is a bad example, just that additional examples would help people like me. IMHO, at least these two examples should be added:

  1. A simple example limited to Basic filters and |=.
  2. An example limited to Basic filters and |= demonstrating how to "modify" a nested property and return it a la sed -e 's/few/many/g'.

Environment (please complete the following information):

  • OS and Version: [e.g. macOS, Windows, Linux (please specify distro)]: Windows 10, WSL Ubuntu
  • jq version [e.g. 1.5]: 1.6
@itchyny itchyny added the docs label Feb 4, 2024
@wader
Copy link
Member

wader commented Feb 9, 2024

The wiki has a quite good step by step article how assignment works https://github.com/jqlang/jq/wiki/Internals:-jq-Assigment-Operators but it's way way too detailed for the manual. A similar but much simpler step by step guide might be interesting to have?

@DanKaplanSES
Copy link
Author

DanKaplanSES commented Mar 7, 2024

@wader I've only skimmed this link, but like you said, it looks pretty thorough. Maybe would suffice to link to it in this section of the documentation, kind of like a, "See more" link? I didn't know this wiki existed, though it didn't occur to me that it might.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants