How to get a summary of the contents of a JSON file ? #3215
Replies: 2 comments 4 replies
-
Hey! maybe have a look at these:
Some snippets you do with jq: # ugly summerise unique paths
$ jq -r '[path(..) | map(if type == "number" then "[]" end) | join(".")] | unique[]' file.json
# truncate arrays
$ jq '(.. | arrays) = .[0:2]' file.json I might dump more examples when i have time... i spend quite a lot of time digging thru files in various formats 😄 |
Beta Was this translation helpful? Give feedback.
-
Welcome to the wonderful world of jq! jq is very handy for the type of challenge you describe, and I would say that the investment in learning jq that might be involved is very likely to be worth your while. To address your question more directly, let me suggest you start with things like If you find the file has a very large number of top-level JSON values, you could determine their types by:
To replace each array by its length, you could write: If you want to infer a schema for the entire file, then there are ways to do that too. See e.g. my own schema.jq
I'd suggest that after you're more familiar with jq and your file, you pose some more targeted questions on |
Beta Was this translation helpful? Give feedback.
-
There is this undocumented JSON file that has > 1M lines that I have to make sense of.
Is there a type of query that will show the JSON contents but limited to N (N=3?) elements at most of any array / object, and list the total number of elements ... just so I can understand what's in it ?
I also tried to dig into the JSON file one level at a time, but I didn't find a
maxdepth
option, or akeys(.)
operator, that would only list the keys of the object but not its contents. Then I could try to navigate interactively.Likely I'm going this the wrong way, and there is another approach to this. Any pointers would be most welcome 😄
thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions