是否可以使用xidel或其他命令行工具从一个文件列出/生成所有JSON Pointers?
我试过了
xidel test.json -e '$json()'但是它只列出顶级字段,而我想要一个递归列表,就像我在xmlstarlet el -a中得到的那样。
发布于 2016-06-18 22:55:13
您可以为此声明一个递归函数:
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, "")
'https://stackoverflow.com/questions/37892961
复制相似问题