Skip to content

Conversation

@rgarcia
Copy link
Contributor

@rgarcia rgarcia commented Jan 12, 2026

Summary

  • When using -o json, the CLI was re-marshaling SDK response structs with json.MarshalIndent(), which included Go zero values for fields not present in the API response (e.g., deleted_at, persistence, profile, viewport)
  • Now uses the SDK's RawJSON() method which preserves the original API response, only outputting fields that were actually returned
  • Adds PrintPrettyJSON and PrintPrettyJSONSlice helpers in pkg/util/json.go that pretty-print the raw JSON from SDK response types

Before

{
  "cdp_ws_url": "wss://...",
  "created_at": "2026-01-12T02:41:42.658978979Z",
  "session_id": "wvmx4yt5afram2xobclje52x",
  "timeout_seconds": 60,
  "deleted_at": "0001-01-01T00:00:00Z",
  "kiosk_mode": false,
  "persistence": {"id": ""},
  "profile": {"id": "", "created_at": "0001-01-01T00:00:00Z", ...},
  "viewport": {"height": 0, "width": 0, "refresh_rate": 0}
}

After

{
  "browser_live_view_url": "https://...",
  "cdp_ws_url": "wss://...",
  "created_at": "2026-01-12T02:49:16.736473188Z",
  "headless": false,
  "session_id": "tpuq0sl28j5d8par13mqo79d",
  "stealth": false,
  "timeout_seconds": 60
}

Test plan

  • All existing tests pass (make test)
  • Tested kernel browsers create --output json - no zero-value fields
  • Tested kernel browsers list --output json - no zero-value fields

Note

Standardizes --output json to pretty-print the original API response using SDK RawJSON() instead of re-marshaling Go structs.

  • Adds pkg/util/json.go with PrintPrettyJSON and PrintPrettyJSONSlice helpers that indent raw SDK JSON
  • Refactors JSON output across commands (app, deploy history, browser-pools, browsers incl. replays/process/fs, extensions, proxies) to use the new helpers; consistent empty slice handling
  • Special-case browsers view to emit { "liveViewUrl": ... } with proper JSON escaping
  • Updates tests (browsers_test.go) to validate pretty JSON output using populated RawJSON()

Written by Cursor Bugbot for commit beccbd7. This will update automatically on new commits. Configure here.

When using -o json, the CLI was re-marshaling SDK response structs with
json.MarshalIndent(), which included Go zero values for fields not
present in the API response (e.g., deleted_at, persistence, profile,
viewport).

This change uses the SDK's RawJSON() method which preserves the original
API response, only outputting fields that were actually returned.

Adds PrintPrettyJSON and PrintPrettyJSONSlice helpers in pkg/util/json.go
that pretty-print the raw JSON from SDK response types.
Copy link
Contributor

@tembo tembo bot left a comment

Choose a reason for hiding this comment

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

Nice cleanup overall — switching -o json to the SDK’s RawJSON() avoids the zero-value field noise, and the call sites read a lot cleaner.

Two small things in the new helpers:

  • PrintPrettyJSON currently prints raw JSON on json.Indent failure and then returns nil. Since callers already propagate the error, returning the indent error would make unexpected/invalid RawJSON() failures easier to notice.
  • PrintPrettyJSONSlice double-indents elements on the success path (prefixing in json.Indent and then adding another two spaces). Dropping the extra prefix keeps output consistent with the fallback branch and typical MarshalIndent formatting.

Everything else in the diff looks solid, and the test update to populate RawJSON() via json.Unmarshal makes sense.

Comment on lines 25 to 29
if err := json.Indent(&buf, []byte(raw), "", " "); err != nil {
// If indentation fails, print the raw JSON as-is
fmt.Println(raw)
return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

PrintPrettyJSON currently swallows json.Indent errors and always returns nil, which makes it harder to detect when RawJSON() is unexpectedly empty/invalid. Since callers already return util.PrintPrettyJSON(...), it might be better to propagate the error.

Suggested change
if err := json.Indent(&buf, []byte(raw), "", " "); err != nil {
// If indentation fails, print the raw JSON as-is
fmt.Println(raw)
return nil
}
var buf bytes.Buffer
if err := json.Indent(&buf, []byte(raw), "", " "); err != nil {
return err
}
fmt.Println(buf.String())
return nil

Comment on lines 52 to 59
if err := json.Indent(&elemBuf, []byte(raw), " ", " "); err != nil {
// Fallback to raw if indentation fails
buf.WriteString(" ")
buf.WriteString(raw)
} else {
buf.WriteString(" ")
buf.Write(elemBuf.Bytes())
}
Copy link
Contributor

Choose a reason for hiding this comment

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

In PrintPrettyJSONSlice, the else path double-indents each element: json.Indent(..., prefix=" ") already prefixes the first line, and then you add another buf.WriteString(" ") before writing elemBuf. This makes the indent differ between the success and fallback branches.

Suggested change
if err := json.Indent(&elemBuf, []byte(raw), " ", " "); err != nil {
// Fallback to raw if indentation fails
buf.WriteString(" ")
buf.WriteString(raw)
} else {
buf.WriteString(" ")
buf.Write(elemBuf.Bytes())
}
var elemBuf bytes.Buffer
if err := json.Indent(&elemBuf, []byte(raw), " ", " "); err != nil {
// Fallback to raw if indentation fails
buf.WriteString(" ")
buf.WriteString(raw)
} else {
buf.Write(elemBuf.Bytes())
}

- Return json.Indent error in PrintPrettyJSON instead of swallowing it
- Fix double-indentation in PrintPrettyJSONSlice by removing extra prefix
- Use json.Marshal for liveViewUrl to ensure valid JSON escaping
@rgarcia rgarcia requested a review from tnsardesai January 12, 2026 10:37
…Slice

json.Indent only adds the prefix after newlines, not before the first
character. This adds the 2-space indent before writing each element to
ensure proper JSON array formatting.
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.

2 participants