360 Secure SkillHub
360 安全技能中心

Jsonpath Query

这是一款基于JSONPath表达式的JSON数据处理工具,核心功能包括查询提取、路径遍历、多值提取、表达式验证等,支持递归检索、通配符、数组切片、过滤条件等语法。典型场景:从JSON文件/标准输入提取指定数据、CI环境校验数据存在性、查看JSON结构路径。输入可为JSON文件或管道输入,输出支持JSON、单行、CSV等多种格式。

charlie-morrison
charlie-morrison
热度 51.47
最近更新 2026-05-11 17:42:36
分类:数据依赖:代码执行 / 读写文件应用场景:数据处理

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add jsonpath-query
Metadata
name
jsonpath-query
description
Query JSON data using JSONPath expressions. Use when asked to extract, filter, search, or navigate JSON data. Supports recursive descent, wildcards, array slicing, filter expressions, and union selections. Triggers on "JSONPath", "JSON query", "extract from JSON", "JSON filter", "jq alternative", "json path", "query json".

JSONPath Query Tool

Query JSON data using JSONPath expressions with recursive descent, wildcards, filters, and slicing.

Query

# From file
python3 scripts/jsonpath.py query '$.store.book[0].title' -f data.json

# From stdin
cat data.json | python3 scripts/jsonpath.py query '$.store.book[*].author'

# Recursive descent (find all 'name' fields at any depth)
cat data.json | python3 scripts/jsonpath.py query '$..name'

# Array slicing
cat data.json | python3 scripts/jsonpath.py query '$.items[0:5]'

# Filter (price < 10)
cat data.json | python3 scripts/jsonpath.py query '$.store.book[?(@.price < 10)]'

# Wildcard
cat data.json | python3 scripts/jsonpath.py query '$.store.*'

# Count matches
cat data.json | python3 scripts/jsonpath.py query '$.users[*]' --count

# First match only
cat data.json | python3 scripts/jsonpath.py query '$.items[*].id' --first

# Exit 1 if no matches (CI-friendly)
cat data.json | python3 scripts/jsonpath.py query '$.missing' --exit-empty

List Paths

# Show all available paths in JSON data
cat data.json | python3 scripts/jsonpath.py paths

# Limit depth
cat data.json | python3 scripts/jsonpath.py paths --depth 3

Extract Multiple Values

# Named extractions
cat data.json | python3 scripts/jsonpath.py extract 'name=$.user.name' 'emails=$.user.emails[*]'

Validate Expression

python3 scripts/jsonpath.py validate '$.store.book[?(@.price > 10)]'

Output Formats

python3 scripts/jsonpath.py query '$.items[*]' -f data.json --format json    # default
python3 scripts/jsonpath.py query '$.items[*].id' -f data.json --format lines # one per line
python3 scripts/jsonpath.py query '$.items[*]' -f data.json --format csv      # CSV for objects

JSONPath Syntax

Expression Description
$ Root object
.key Child key
[0] Array index
[0:5] Array slice (start:end)
[0:10:2] Array slice with step
[*] All elements
..key Recursive descent
[?(@.price<10)] Filter expression
['key'] Bracket notation
[0,1,2] Union (multiple indices)