How does one go about contructing the path to a deeply nested field from a large json document.
The approach I've typically used is to flatten the JSON using a jq
expression.
map
(
with_entries(select(.key != "fields"))
+
(.fields | with_entries(.value = .value[0]))
)
However, I'm preparing for a practical test, where jq will not be available. I've reverted to scrolling up and down with less to figure out document structure.
Is there an easier way to do this with standard Linux tools?
vim
with a JSON filetype and some folding perhaps, but I sense that's not really in the spirit of the task you've been given. – eleventyone Aug 15 '20 at 12:39jq
is the standard Linux tool to handle json.vim
's own syntax folding abilities can certainly be better than a plainless
over the document but I suspect it is available only on fullvim
, not onvim-tiny
which is often the default on e.g. Ubuntu systems. Will you be allowed to use your own script on (or perhaps copy&paste from/to) that lab's linux vanilla system? – LL3 Aug 17 '20 at 14:59:set foldmethod=syntax
and create folds withza
. Works quite well to drill down/out of a json. You're right it will be tricky if it doesn't have full vim. Which is quite likely given that test is on Ubuntu 16 Server edition. You're not allowed to open any internet sites during exam. It doesn't say anything about installing packages, but I'm not willing to risk it. Worst case, I think I'll use Python 2.7 json parsing. – Kshitiz Sharma Aug 17 '20 at 20:44