CLI with --json: Process Same-QR outputs in scripts
Why JSON for programs
Command-line programs usually respond for humans: a sentence, a table. A script would have to chop up this text and hope the format never changes. JSON is a text format for structured data that practically any language can read. A CLI with JSON output delivers the same information in a fixed format.
The --json option
Every command in the sameqr-CLI supports --json. Instead of a table, the API response is then returned as JSON:
sameqr qr list --json
sameqr qr create --name "Plakat Nord" --url https://example.com/aktion --json
sameqr seite list --jsonProcessing with jq
In shell scripts, the small tool jq extracts individual values. This is how you list the name and scans of all QR codes or store the identifier of a new QR code:
sameqr qr list --json | jq -r '.codes[] | "\(.name);\(.scanCount)"'
id=$(sameqr qr create --name "Plakat Süd" --url https://example.com/aktion --json | jq -r .id)
sameqr qr stats "$id"Detect errors in scripts
With --json, errors also come as JSON, specifically on the error output so they do not mix with the actual data. Additionally, the return QR code indicates the type of error:
- 0: everything is fine.
- 2: incorrect or missing input, such as a forgotten --name.
- 3: not logged in or invalid key.
- 4: no permission, such as a "read only" key or a plan limit.
- 1: another API error.
Break loops on the first error instead of producing the same error a hundred times, for example with "|| break" after the command.
Examples of workflows
- A list of locations is converted to QR codes; JSON responses are saved in a file for the print shop.
- A monthly job saves "sameqr qr list --json" as the baseline for the scan report.
- A coding agent calls the CLI itself and reads the JSON responses to plan the next steps.
Conclusion: why Same-QR
The sameqr-CLI is built for scripts: JSON on demand, errors cleanly separated with distinct return QR codes, keys from the environment rather than the command line. This turns individual commands into reliable workflows, with Same-QR in every plan.
Get started right away: sign up for free at sameqr.com, 20 dynamic QR codes are free forever. API, CLI and MCP server are included in every plan, and the documentation is at sameqr.com/entwickler.
Frequently asked questions
No. At the terminal, normal output is more pleasant. --json is intended for scripts and programs.
To the error output; with --json, also as JSON with status, QR code, and message. The data itself is on the normal output.
By the return value 3. Return value 4 means missing permission.
New articles straight to your inbox
Tips on dynamic QR codes, new features, no spam. Unsubscribe any time.
By subscribing you consent to receiving the newsletter. You can withdraw consent at any time via the unsubscribe link in every email.