-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Open
Description
Content & configuration
Is your feature request related to a problem?
Yes, Swagger UI currently lacks automatic or on-demand formatting for JSON request bodies. When working with complex or deeply nested JSON structures, the absence of indentation and formatting reduces readability and increases the likelihood of user errors.
- Harder to visually parse and edit non-trivial JSON payloads
- More prone to human errors such as missing commas or unmatched braces
- Forces users to rely on external editors or browser extensions to properly format their request JSON
Describe the solution you'd like
Add JSON formatting support for request body editors when the request’s media type is application/json.
- Detect if the request body content type is JSON
- Provide a “Format JSON” button above or beside the textarea
- On click:
- Validate the current input using
JSON.parse - If valid, reformat using
JSON.stringify(value, null, 2) - If invalid, display an inline error message such as:
"Unable to format: invalid JSON."
- Validate the current input using
- Should not auto-format on every keystroke to avoid disrupting partial edits
- Should not be enabled for non-JSON media types (XML, text, YAML, binary, form-data, etc.)
This approach minimizes risk and avoids unexpected behavior while offering a clear UX improvement.
Describe alternatives you've considered
- Writing JSON in external code editors
This is currently the only reliable option but breaks the flow.
Additional context
I am willing to open a PR implementing this functionality once approved.
The implementation requires no new dependencies—JSON.parse and JSON.stringify are sufficient.
Metadata
Metadata
Assignees
Labels
No labels