-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Question on how to input value of a node A, and get sibling node B's value back #663
Comments
@RickCogley - There are of course many ways to skin a cat, but if I understand what you're asking for correctly, then I believe the following hints should suffice: Step 1:
Step 2:
|
@pkoppstein, thank you very much! That works like a charm! (I did not know you can tokenize an input stream to |
While @pkoppstein answered your question, I'd like to shed some light on what's actually happening in (Note that "object" below means a JSON object (a key-value map). "value" is used to mean any valid JSON type (number, string, object, array, null))
Admittedly, this is not my best explanation of what's happening here. The basic concept is that when Any further questions, just ask and we'll be more than happy to help! |
@wtlangford, thanks! Yes, it felt like a cartesian product of two data sets, that you sometimes see in SQL syntax. I appreciate the extra explanation. Once I get the scripts working, I will write a little Cookbook entry for the wiki, referencing this Issue. I do have another question which I intend to articulate in detail, but the gist is I want to grab two json streams, one a list of people and some basic attributes about them, and two a list of working days in this month. This time I do want to do a cartesian product of the two, resulting in one big stream with an entry per every date for every person. I may need help with it. I appreciate the quick assistance, sincerely. |
@RickCogley - You're welcome. I thought a solution-oriented response would be both simpler and more helpful, but your approach ("to apply the contents of that variable to the json, to get the sibling of the table alias, the table name") can of course be made to work, too. In essence it would be based on this:
Regarding your two JSON streams -- version 1.4 of jq isn't very flexible when it comes to handling more than one JSON stream at a time, but you may find that the -s ("slurp") option will be part of the solution. |
Thanks again, @pkoppstein. I'll try that too, as well as look into slurp when I start trying to accomplish the other solution. |
FYI I added a recipe to the Cookbook on the wiki. |
Thanks! |
Hello - I just noticed that there are a few general questions on here, under the query tag. I've read the documents but, I guess I'm floundering around. I hope you'll indulge a usage question.
Given sibling nodes A and B in json, where A and B are unique to the json stream I am looking at, and never repeated, my goal is to supply A and have B returned. Kind of a "lookup" concept.
I will access my json streams via a REST interface, using curl in a shell script. The json looks something like this:
Actually, the pure json stream has no newlines, so passing it through '.' fixes that.
I can get a list of table aliases, using this command against a file I got via curl:
The tablealiases.txt file then looks like this, with one table alias per line:
Then I can perform some action on the REST interface using that file as input, using a while loop like:
But what I'd like is, the result json
Table-$t-getinfo.json
to be named using two items from the original json. Instead ofTable-t_12341-getinfo.json
, I'd like to haveTable-t_12341-Company-getinfo.json
, for readability.When I do my while/do/done loop, I already have variable
$t
containing the table alias, so I'd like to apply the contents of that variable to the json, to get the sibling of the table alias, the table name.I have been using jqplay.org to try to do things like this:
... but it just returns the table names multiple times, like:
Other variants like trying to use the variable in the filter content to pinpoint the record, like:
... are not working at all, yielding an error like:
I hope someone could kindly point me in the right direction.
Thanking you in advance.
Sincerely,
Rick
The text was updated successfully, but these errors were encountered: