-
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
Are wildcard values possible? #82
Comments
My understanding (as a user) is that Thus you would need
This can be simplified a bit. First,
Next, the whole
Finally, to answer your second question, jq doesn't have an
|
13ren, thank you very much for your clear and detailed response. I'd been tearing out my hair trying to understand this. I have two further questions related to my example files. Firstly, given that
finds the target record for me, is there a way to return just the whole records key? in this case A0002. (I can see the keys operator, but can't see how to use it to achieve this.) Secondly, Having passed back just the key, eg A0002 it would be great to pass back the file-name that the record was found in also, eg company1.json. Is there an elegant way to do this? (My thoughts were to add a top level key "FILENAME": "company1.json to the input file and reference it with .FILENAME, but I get jq: error: Cannot index string with string if I do that) |
To return the key (fieldname), you have to use that in the lookup. Because jq only has one stream argument, and we need both the object we are addressing and the key/fieldname, we need to store one of them in a variable. In the above, the object is stored in variable I think your idea for a top-level key should work. Note that the wildcard code will attempt to lookup (or "index") the field
You can factor out the
Though maybe it's clearer, and more jq-like, to just filter it out in a separate step:
BTW: As an aside, you could even have a separate string outside the object even though it's not valid josn (because jq accepts a stream of json instances), like:
Finally, there is a way to do partially want you want. Although jq doesn't distinguish between different input files, it does distinguish between json instances in a stream. The BTW: I think you might be interested in this little tutorial towards the end of the docs, about more complex queries: http://stedolan.github.com/jq/manual/#VariablesandFunctions |
I'm beginning to feel like I'm taking advantage of you, If I can crack this, then I'm all set to solve my task If I alter the input file to something like
and then use
I get this
whoo-hoo!!! is this the best way to tackle this or is there a more jq way? |
You can fix that by passing on your understanding to the next asker... also a tremendous way to consolidate your understanding. ;-) |
I especially appreciated the example of how to use contains(). |
(Sorry for asking a question here, I couldn't find a forum for jq)
I have a pair of artificial and convoluted files
company1.json
company2.json
I can run the following
which returns
Is there a way I can wildcard the values A0002 and T2?
eg:
also can I do some form of string match
eg
The text was updated successfully, but these errors were encountered: