Skip to content

fix(json): quote object keys in schema output - #1023

Closed
CastawayEGR wants to merge 2 commits into
rtk-ai:developfrom
CastawayEGR:fix/json-unquoted-keys-v2
Closed

CastawayEGR wants to merge 2 commits into
rtk-ai:developfrom
CastawayEGR:fix/json-unquoted-keys-v2

Conversation

@CastawayEGR

Copy link
Copy Markdown

Object keys in compact_json() and extract_schema() were missing double quotes, producing invalid JSON that breaks jq, python3 json.load(), etc.

Wraps all key formatting in "key": instead of key:.

Fixes #1015

Both functions formatted JSON object keys without double quotes,
producing invalid JSON that broke jq, python json.load(), etc.

Fixes rtk-ai#1015
@pszymkowiak pszymkowiak added bug Something isn't working effort-small Quelques heures, 1 fichier labels Apr 4, 2026
@pszymkowiak

Copy link
Copy Markdown
Collaborator

[w] wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟢 Risk low

Summary

Fixes invalid JSON output from compact_json() and extract_schema() by wrapping object keys in double quotes. Previously, keys were emitted without quotes, breaking standard JSON parsers like jq and Python's json.load().

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Linked issues: #1015


Analyzed automatically by wshm · This is an automated analysis, not a human review.

@em0t em0t left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this locally against current master and this branch, and I still see blocking issues before merge.

First, rtk json <file> still does not produce valid JSON for object output because object entries are not comma-separated, so jq and python -c 'import json,sys; json.load(sys.stdin)' still fail on simple cases.

Second, keys are wrapped in quotes but not escaped, so inputs containing " or \ in object keys still produce invalid output.

I also don’t think --schema currently satisfies the “valid JSON” claim, because tokens like int, string, and [int] (3) are not JSON values.

I’d either narrow the PR description to “quote keys in display output” or extend the implementation/tests to cover actual JSON-valid output.

@pszymkowiak

Copy link
Copy Markdown
Collaborator

@CastawayEGR — gentle ping: still on this one? em0t's review has 3 points to address before it can merge (comma-separated object entries, key escaping, and the --schema "valid JSON" claim). Happy to move it forward once those are sorted — just let us know if you'd like to continue.

@pszymkowiak

Copy link
Copy Markdown
Collaborator

Closing: already fixed on develop. The scenario in #1015 (rtk curl returning invalid JSON) was resolved by 71baf2b and 02da3d0, which stopped routing curl's JSON bodies through the schema formatter; rtk curl ... | jq parses on current develop. What this diff still touches, rtk json, is a lossy summary format by design and would not become valid JSON with quoted keys alone (entries are not comma-separated, keys are not escaped). Thanks for the PR.

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

Labels

bug Something isn't working effort-small Quelques heures, 1 fichier

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(json): curl filter outputs invalid JSON — object keys lose double quotes

3 participants