-
-
Notifications
You must be signed in to change notification settings - Fork 164
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
Document variable assignment to a JSON (Dict) attribute #1129
Comments
Thanks for the feedback! I pushed a change with some example, which will be out with the next release. A full reference will have to wait for #1130 |
Thank you! |
I do have a followup question: In my example above I'm basically converting the Oil variable
But this doesn't seem to work as it assigns the literal string
I've tried different variations/styles of setting variables but I can't seem to get what I'm looking for. Is there a way to do this natively without translating back and forth between JSON and passing to/from STDOUT? |
Ahh so this is actually a side effect of fixing #937 in the most recent release release. It used to be that we disallowed shell style assignment in Oil
and allowed
Now it has to be
So as a side effect now allow I think we can simply disallow it again ... But not allow Thanks for the feedback! I was thinking about this too |
Beautiful - yes, the
|
The doc is released: https://www.oilshell.org/release/0.10.1/doc/json.html I have an idea for |
Let me know if you see anything else. Generally the expression language is like Python This doc is not yet polished, but it gives a "diff" vs Python: https://www.oilshell.org/release/latest/doc/oil-vs-python.html |
I ended up turning this into a blog post. Let me know if you would like any updates to the Oil section. Thanks! https://blog.kellybrazil.com/2022/05/19/working-with-json-in-various-shells/ |
Great post, thanks! I'm slightly surprised at how much convergence there is :) This reminds me a bit of issue #736 -- I feel like a shell could make it easier to install / try new tools without root access, and without messing with PATH. That always seems to be a barrier for trying new tools That and versioning of the tools |
In the documentation it shows how to read JSON into a variable and write it out, but doesn't show how you can select a portion of the JSON and assign that to a variable as a scalar, array, or map.
https://github.com/oilshell/oil/blob/master/doc/json.md
I'm working on adding examples of how to use
jc
in alternative shells. I was able to assign JSON to a variable, but I'm not sure the recommended way to further filter the variable and assign that value to another variable. This is what I came up with:https://github.com/kellyjonbrazil/jc/wiki/Using-jc-With-Different-Shells
Is this a good way to do it or is there a better way to slice the data once it is read into Oil?
The text was updated successfully, but these errors were encountered: