Reputation: 1457
Is it possible to list/generate all the JSON Pointers from a file using xidel or another command line tool?
I've tried with
xidel test.json -e '$json()'
But it only lists the top-level fields, while i want a recursive listing like the one i get with xmlstarlet el -a
.
Upvotes: 1
Views: 319
Reputation: 16917
You can declare a recursive function for that:
xidel test.json -e '
declare function escape ($s) { replace(replace($s, "~", "~0"), "/", "~1") };
declare function enum($v, $pointer) {
typeswitch ($v)
case array() return $v() ! enum(., $pointer || "/" || string(position() - 1))
case object() return $v() ! enum($v(.), $pointer || "/" || escape(.))
default return $pointer
};
enum($json, "")
'
Upvotes: 1