Skip to content

fix: JSON response examples being saved as [object Object] in YAML format#6488

Merged
bijin-bruno merged 1 commit intousebruno:mainfrom
sanjaikumar-bruno:fix/yml-example-response-content-serialization
Dec 23, 2025
Merged

fix: JSON response examples being saved as [object Object] in YAML format#6488
bijin-bruno merged 1 commit intousebruno:mainfrom
sanjaikumar-bruno:fix/yml-example-response-content-serialization

Conversation

@sanjaikumar-bruno
Copy link
Member

@sanjaikumar-bruno sanjaikumar-bruno commented Dec 23, 2025

BRU-2389

Issue:
When saving JSON response examples in YAML format, the response body content was being saved as [object Object] instead of the actual JSON data. This occurred because String() was used to convert the content, which doesn't properly serialize objects.

Fix:
Updated stringifyHttpRequest.ts to check the content type before serialization:

  • If content is a string, use it as-is
  • Otherwise, use JSON.stringify() to properly serialize objects, arrays, and primitives

The fix is similar to how we are handling JSON in bru,

if (responseBody) {
bru += ' body: {\n';
if (responseBody.type) {
bru += ` type: ${responseBody.type}\n`;
}
if (responseBody.content !== undefined) {
let contentString = typeof responseBody.content === 'string' ? responseBody.content : JSON.stringify(responseBody.content, null, 2);
bru += ` content: '''\n${indentStringCustom(contentString, 6)}\n '''\n`;
}
bru += ' }\n\n';
}
bru = stripLastLine(bru);
bru += '}';
}

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 23, 2025

Walkthrough

Modified stringifyHttpRequest.ts to improve example response body serialization. When stringifying response bodies, non-string content is now JSON-stringified with pretty-printing formatting instead of direct coercion, ensuring consistent readable output.

Changes

Cohort / File(s) Change Summary
Response body serialization
packages/bruno-filestore/src/formats/yml/items/stringifyHttpRequest.ts
Introduced contentString variable to handle content formatting—strings used as-is, non-strings JSON-stringified with indentation for readability

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested labels

size/XS

Suggested reviewers

  • lohit-bruno
  • helloanoop
  • bijin-bruno

Poem

✨ Pretty JSON, line by line,
No more squished strings in the design,
Stringify with care and grace,
Readability wins the race! 📋

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main fix: preventing JSON response examples from being incorrectly serialized as '[object Object]' in YAML format.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@bijin-bruno bijin-bruno merged commit 87c8934 into usebruno:main Dec 23, 2025
8 checks passed
@sanjaikumar-bruno sanjaikumar-bruno deleted the fix/yml-example-response-content-serialization branch December 23, 2025 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants