I have a very very big JSON and I'd like to check the path to some keys. Pretty printing doesn't help if the JSON is very large and lot of hierarchies. I'm using Sublime 3 and jq together with the Pretty JSON plugin. Is there a way to know the full path(s) to a given key using the jq tool or any other way? I could write a JSON parser in some language and do it but I need just to figure out quickly where things are.
Asked
Active
Viewed 432 times
0
-
at least, share the link to your json and post the expected path to some specified key – RomanPerekhrest Oct 11 '17 at 12:36
-
is a *huge* JSON – SkyWalker Oct 11 '17 at 12:41
-
good luck ... with *huge JSON* – RomanPerekhrest Oct 11 '17 at 12:46
-
Is the key unique that you can find it at all without know the path to begin with? – chepner Oct 11 '17 at 13:43
-
Is this not essentially a duplicate of https://stackoverflow.com/questions/39800718/how-to-use-jq-to-find-all-paths-to-a-certain-key ? – peak Oct 11 '17 at 14:05
-
Somewhat yes but I tried that solution from Sublime and didn't work. – SkyWalker Oct 11 '17 at 14:35
-
What exactly did you try? Have you tried it using jq directly? Which version of jq were you using? – peak Oct 11 '17 at 15:34
-
is the key unique? Would you find it by searching for `"
":` in the text, if you could? - Other question: is the JSON pretty-printed? – Walter Tross Oct 11 '17 at 16:26 -
2It looks like you'll have to get in contact with the author of that plugin to add those features. At first glance, it appears it's just calling jq on file itself and you provide a filter. They'll probably have to add ways to set additional options for the filters. – Jeff Mercado Oct 11 '17 at 18:37
1 Answers
1
It would be easier to answer more precisely if you can provide a small sample of your data and the desired output but in any event the --stream option may be what you want. From the documentation:
Streaming
With the --stream option jq can parse input texts in a streaming fashion, allowing jq programs to start processing large JSON texts immediately rather than after the parse completes. If you have a single JSON text that is 1GB in size, streaming it will allow you to process it much more quickly.
However, streaming isn’t easy to deal with as the jq program will have
[<path>, <leaf-value>]
(and a few other forms) as inputs.
Here are some existing answers you may want to review.
The JQ Cookbook also has an example: