← Back to blog
AI & Automation2 min read

CLI with --json: Process Same-QR outputs in scripts

Bild von Unsplash

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 --json

Processing with jq

In shell scripts, the small tool jq extracts individual values. This is how you list the name and scans of all codes or store the identifier of a new 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 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 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 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, two dynamic QR codes are free forever. API, CLI and MCP server are included in every plan, and the documentation is at sameqr.com/entwickler.

Create dynamic QR codes for free
Start with 2 dynamic QR codes that are free forever. No subscription, no credit card.
Start free now →

Frequently asked questions

Do I always have to use --json?

No. At the terminal, normal output is more pleasant. --json is intended for scripts and programs.

Where do error messages go?

To the error output; with --json, also as JSON with status, code, and message. The data itself is on the normal output.

How does my script recognize a missing key?

By the return value 3. Return value 4 means missing permission.

Reserve a spot

Reserve your spot before we go live.

One email as soon as the tool goes live — including pricing and the free plan. No spam, unsubscribe any time.

Only until launchLaunching in the next few weeks
  • Your free account is reserved — there is nothing to pay yet anyway
  • 90 days of unlimited destination changes instead of 30, only for early sign-ups
  • Launch price locked in, even if we raise prices later

By subscribing you consent to receiving the newsletter. You can withdraw consent at any time via the unsubscribe link in every email.

Keep reading