Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Json validation on beautify #1365

Open
avollmaier opened this issue Apr 22, 2024 · 1 comment
Open

Json validation on beautify #1365

avollmaier opened this issue Apr 22, 2024 · 1 comment

Comments

@avollmaier
Copy link

Currently there is no json validation when beautifying json responses - only a comment that beatification should not occur in the catch

public formatBody() {
const activeRouteResponse = this.store.getActiveRouteResponse();

if (!activeRouteResponse.body) {
  return;
}

const contentType = GetRouteResponseContentType(
  this.store.getActiveEnvironment(),
  activeRouteResponse
);

if (stringIncludesArrayItems(ParsedJSONBodyMimeTypes, contentType)) {
  try {
    this.activeRouteResponseForm
      .get('body')
      .setValue(
        JSON.stringify(
          JSON.parse(activeRouteResponse.body),
          undefined,
          INDENT_SIZE
        )
      );
  } catch (e) {
    **// ignore any errors with parsing / stringifying the JSON**
  }
}

}

@avollmaier avollmaier changed the title Json Validation on beautify Json-Validation on beautify Apr 22, 2024
@avollmaier avollmaier changed the title Json-Validation on beautify Json validation on beautify Apr 22, 2024
@255kb
Copy link
Member

255kb commented Apr 26, 2024

Thanks for opening the issue, but I don't think the PR you opened is the right way to improve this.
Most of the time the body will be invalid as a lot of people are using templating helpers (Handlebars). Having a popup most of the time someone is clicking on this link is not a good improvement. I will close it.

I'm not sure what is the right way to improve the experience. But I would prefer a more "clever" solution like:

  • beautify the JSON if valid
  • if not valid, only do basic indentation of the code

I didn't find a Handlebars beautifier that could work.

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 a pull request may close this issue.

2 participants