Skip to content

fix(curl): preserve valid JSON output for piping (#1015) - #1016

Closed
pszymkowiak wants to merge 1 commit into
developfrom
fix/json-keys-quotes
Closed

pszymkowiak wants to merge 1 commit into
developfrom
fix/json-keys-quotes

Conversation

@pszymkowiak

Copy link
Copy Markdown
Collaborator

Summary

Problem

rtk curl https://api.example/endpoint | python3 -c 'json.load(sys.stdin)' failed because:

  1. extract_schema() replaced values with type names (int, string, bool)
  2. Object keys were unquoted ({name: string} instead of {"name": "string"})

Fix

  • curl_cmd: JSON responses pass through unchanged (no schema transform)
  • json_cmd: keys are now double-quoted in extract_schema() for other consumers
  • Non-JSON output still gets truncated as before

Test plan

  • cargo test curl_cmd — 4 tests pass
  • cargo test json_cmd — 9 tests pass
  • Manual: rtk curl <api> | python3 -c 'json.load(...)' works

curl filter was converting JSON values to type names (extract_schema),
producing invalid output that broke downstream JSON parsers (python, jq).

Changes:
- curl_cmd: pass JSON through unchanged instead of schema transform
- json_cmd: quote object keys in extract_schema for valid JSON output
- Added tests for JSON validity and quoted keys
@pszymkowiak

Copy link
Copy Markdown
Collaborator Author

Closing in favor of #1602, which addresses the same underlying problem (#1536 — rtk curl truncating large JSON mid-stream and producing invalid output) but on the current develop shape of curl_cmd.rs. Since this PR was opened, the schema-conversion path it targeted has been refactored away and replaced with a hardcoded 500-byte truncation + tee hint, so a clean rebase wasn't practical.

#1602 keeps the spirit of the JSON-passthrough idea here, adds an IsTerminal gate so pipes/redirects also receive the full body (also closes #1282), and ports the test coverage.

The json_cmd.rs::extract_schema key-quoting change isn't carried over: even with quoted keys, the surrounding pseudo-schema (int, string, array) isn't valid JSON, so the change adds tokens without making the output parseable. If we want a real "valid JSON schema" output mode for rtk json it should be a separate, deliberate feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant