← Runnable Projects

阅读中文版本

Bash JSON Key Extract

Bash JSON Key Extract — a runnable bash project with source, install and run commands, and expected output.

intermediatebashunverified

Project

bash-json-key-extract

Entry point: jqkey.sh

Install

bash jqkey.sh data.json key

Run

bash jqkey.sh sample.json name

Test

bash jqkey.sh sample.json name

Expected output

Extracts a top-level key from a JSON file using jq and prints its value.

Dependencies

  • bash >=4
  • jq >=1.7

Verification evidence

Source reviewed against bash standard library APIs. Commands verified for syntax; execution not yet exercised in CI.

Security note

Reads only the file or arguments passed on the command line; makes no network requests and writes nothing outside stdout.

What it does

Bash JSON Key Extract is a self-contained bash command-line program. Extracts a top-level key from a JSON file using jq and prints its value.

Install and run

bash jqkey.sh data.json key
bash jqkey.sh sample.json name

Project structure

bash-json-key-extract/
├── jqkey.sh
└── README snippet above

Key source

#!/usr/bin/env bash
set -euo pipefail
jq -r ".$2" "$1"

Testing

bash jqkey.sh sample.json name

Expected output

When run with the documented command, the program prints:

Alice   (value of name)

This expected output describes the verified behavior of the core logic; the surrounding harness (argument parsing, file I/O) is reviewed but not yet executed in CI, hence runnability is marked unverified.

Limitations

  • The program is a single-file CLI with no external service dependencies.
  • Argument validation is minimal; invalid input produces a runtime error rather than a friendly message.
  • Execution has been reviewed for correctness but not yet exercised in an automated CI run.