360 Secure SkillHub
360 安全技能中心

Skill 3

这是零依赖的Python JSON工具,核心功能含可配置缩进的格式化、压缩、结构校验(输出统计)、点符号嵌套查询(支持数组索引)、键排序,还支持标准输入适配shell管道。适用于API数据处理、配置文件整理、生产JSON压缩等场景,输入可为文件或管道,输出支持文件或stdout。

claudiodrusus
claudiodrusus
热度 62.12
最近更新 2026-05-11 17:26:48
分类:效率依赖:代码执行 / 读写文件应用场景:数据处理 / 文件转换

安装技能

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

执行命令安装此 skill: npx secure-skills-cli add skill-3
Metadata
name
json-toolkit
description
Swiss-army knife for JSON files. Pretty-print, validate, minify, sort keys, and query with dot-notation paths. Zero dependencies.
triggers
["format json","pretty print json","validate json","query json","minify json","json tool"]

JSON Toolkit

A zero-dependency Python utility for working with JSON data. Validates, formats, minifies, queries, and inspects JSON files — all with Python's standard library.

Features

  • Pretty-print with configurable indentation (2, 4, or any number of spaces)
  • Minify JSON to reduce file size for APIs and storage
  • Validate JSON and get structural stats (type, key count, size)
  • Query nested data with dot-notation paths including array indices
  • Sort keys alphabetically for deterministic output and easier diffs
  • Stdin support for use in shell pipelines with other tools

Usage Examples

Pretty-print a JSON file:

python main.py data.json

Validate without output:

python main.py config.json --validate
# ✓ Valid JSON
#   Type: object (12 keys)
#   Size: 4832 bytes

Query a nested value:

python main.py users.json --query data.users.0.name
# "Alice"

Minify for production:

python main.py config.json --minify -o config.min.json

Sort keys for consistent diffs:

python main.py package.json --sort-keys -o package-sorted.json

Pipe from curl:

curl -s https://api.example.com/data | python main.py - --query results.0

Query Syntax

Use dot notation to navigate nested structures. Array indices are numbers:

  • name — top-level key
  • data.users — nested object key
  • data.users.0 — first element of an array
  • data.users.0.email — field of the first array element
  • config.servers.2.host — deeply nested value

Command Line Options

  • input — JSON file path, or - for stdin
  • -o, --output — Output file (defaults to stdout)
  • --indent N — Indentation spaces (default: 2)
  • --minify — Output minified JSON (no whitespace)
  • --query PATH / -q PATH — Extract a value at the given dot-notation path
  • --validate — Only validate and print stats, no output
  • --sort-keys — Sort object keys alphabetically
  • --json — (implicit) Output is always valid JSON