基于jsonselect的json处理命令行工具
jss的Python项目详细描述
jss是一个json处理命令行工具(如jq)。
与jq不同,它的选择语言是 JSONSelect,它基于css 选择器。无需学习处理json的特殊语言 文件夹。就用一个你已经知道的!你在jss的时间不会 浪费它会让你更好地编写css选择器。
用法
$ pip install -g jss $ cat file.json { "foo": [ "bar", { "baz": "quux" } ], "wut": { "name": "foo", "metadata": { "owner": "danvk", "blah": "whatever" } }, "name": "dan" } # Pull out all values with key "name", from anywhere in the JSON. $ jss .name file.json "foo" "dan" # Remove fields named "metadata", wherever they occur (JSON→JSON transform): $ jss -v .metadata file.json { "foo": [ "bar", { "baz": "quux" } ], "wut": { "name": "foo" }, "name": "dan" } # Keep only fields named "name", plus their ancestors (JSON→JSON transform): $ jss -k .name file.json { "wut": { "name": "foo" }, "name": "dan" } # Keep only top-level entries with "whatever" in some value underneath them: # (JSON→JSON transform using jQuery-style selectors): $ jss -k ':root>*:has(:contains("whatever"))' file.json { "wut": { "name": "foo", "metadata": { "owner": "danvk", "blah": "whatever" } } }