-
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
tool that shows all possible jq paths in a given json file #243
Comments
Can you write that program in jq? I bet it can be done! |
@nicowilliams ... but why ?I'm sure I can be more productive doing pretty much anything else :) |
Excellent @ilyash ! I'm going to use that. I was thinking of doing the same thing. And yes @nicowilliams I did think about how I could have done it in jq. |
@nicowilliams now i have a new crazy jq side project to match my sudoku validator |
Do you think this application could be used to provide autocompletion on the command line? That would be amazing. |
FYI, I believe that this:
empty end))' or, with master, this:
will list all the possible paths. |
@nicowilliams this is completely different output, it's not copy+paste ready to help with building the jq command line. |
@slapresta this is very good idea, not sure yet whether and how this could be implemented. The first concern is that the command is of the form |
+1 to @slapresta 's idea. @ilyash This produces a list of paths in the input:
It's a very simple, trivial program :) |
@nicowilliams You are totally ignoring the differences between outputs and the fact that show-struct is helpful for constructing the path part of jq command. Have you seen the sample output of the show-struct? Let's compare full (but censored) outputs for the same input. show_struct:
In contrast, the jq program above shows:
|
I like the idea of a compact structural overview, but am not as interested in the value or array lengths.
See also |
@joelpurra Very clever! This will come in handy when we have |
@slapresta Your jq sudoku code is very cool. I wonder if you can modify it to take advantage of tail call optimization in |
See discussion regarding the `show-struct` tool by @ilyash. https://github.com/ilyash/show-struct jqlang/jq#243
@joelpurra , I have a sample file (not sure where I got it from, it's just there): [
{"$jt:env": "HOME"},
["$jt:env", "HOME"]
] Both outputs from your snippet and my show_struct are pretty confusing:
and
I guess we could both improve... |
@ilyash: Yes, it's a confusing example =) I have an updated version that works slightly differently. Plan to move it from har-dulcify to jq-hopkok at some point. <temp.json har-dulcify/src/util/structure.sh .
.[]
.[]["$jt:env"]
.[][] Because of the mixed data types, jq doesn't fully agree when using this as input on the same file. |
On Sat, Aug 16, 2014 at 2:51 PM, Ilya Sher notifications@github.com wrote:
A path-based representation of the above text which papers over the |
@nicowilliams or @ilyash what about showing the values of those paths as well? |
If anyone is interested, the following code show all paths with their values: paths(scalars) as $p
| [ ( [ $p[] | tostring ] | join(".") )
, ( getpath($p) | tojson )
]
| join(" = ") Example: $ jq -r '
paths(scalars) as $p
| [ ( [ $p[] | tostring ] | join(".") )
, ( getpath($p) | tojson )
]
| join(" = ")
' <<'INPUT'
{
"a": 1,
"b": [ "red", "green", "blue" ],
"c": {
"d": [
{
"a": 100,
"b": 200,
"c": "x\ny\nz"
},
{
"a": 101,
"b": 201
}
]
}
}
INPUT Output:
|
@ayosec is it possible to have this? thx
Tried it myself but seems alot harder then I expected. |
@gertcuykens - The following produces the output you've indicated you want:
|
yep works awesome thx, wouldn't be able to find it myself in a million years :) PS just made a slide modification else you get double quotes
|
@ilyash - open a buy me a beer / coffee account ... I will be one of the first to send you money ... Your tools has save me and my customers tremendous amount of time ... |
I've been using this syntax jq 'select(objects)|=[.] | map( paths(scalars) ) | map( map(select(numbers)="[]") | join(".")) | unique' That last pipe to unique is also helpful for really large objects. |
( Copy+pasting unanswered email: )
Hi.
I have just prepared a tiny tool that shows all possible jq paths in a given json file. I guess it can help people that use jq. I'm not sure where in the docs it goes. Can you please add a link wherever you think is appropriate?
Please note (also, should be clear to users before following the link) that the script was not heavily tested and I guess is alpha quality in general, quick and dirty, naive implementation.... but still works for me.
https://github.com/ilyash/show-struct
Thanks!
The text was updated successfully, but these errors were encountered: