[GH-ISSUE #4411] [bug]: JSON Prettify adds trailing commas, causing invalid JSON #1615

Closed
opened 2026-03-16 21:07:08 +03:00 by kerem · 8 comments
Owner

Originally created by @ninemind on GitHub (Oct 7, 2024).
Original GitHub issue: https://github.com/hoppscotch/hoppscotch/issues/4411

Originally assigned to: @anwarulislam on GitHub.

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

When using the "Prettify" feature on JSON in the in the request body, trailing commas are added after the last property in an object, resulting in an invalid JSON format that does not conform to the JSON standard.

Steps to reproduce

  1. Open Raw Request Body
  2. Set Content-Type to application/json
  3. Enter a simple JSON object, for example:
{
  "test": 123
}
  1. Click on the "Prettify" button to format the JSON.
  2. Observe that the prettified output contains a trailing comma, such as:
{
  "test": 123,
}

Notice that the resulting JSON is not valid according to the JSON standard.

Environment

Production

Version

Self-hosted

Originally created by @ninemind on GitHub (Oct 7, 2024). Original GitHub issue: https://github.com/hoppscotch/hoppscotch/issues/4411 Originally assigned to: @anwarulislam on GitHub. ### Is there an existing issue for this? - [X] I have searched the existing issues ### Current behavior When using the "Prettify" feature on JSON in the in the request body, trailing commas are added after the last property in an object, resulting in an invalid JSON format that does not conform to the JSON standard. ### Steps to reproduce 1. Open `Raw Request Body` 2. Set `Content-Type` to `application/json` 3. Enter a simple JSON object, for example: ``` { "test": 123 } ``` 4. Click on the "Prettify" button to format the JSON. 5. Observe that the prettified output contains a trailing comma, such as: ``` { "test": 123, } ``` Notice that the resulting JSON is not valid according to the JSON standard. ### Environment Production ### Version Self-hosted
kerem 2026-03-16 21:07:08 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@ninemind commented on GitHub (Oct 7, 2024):

The editor does not provide any indication that the resulting JSON is invalid after adding trailing commas. This lack of validation can lead to confusion, as the JSON appears correct but causes issues when sent in a request. Specifically, many APIs reject the request body or fail to process it correctly due to the invalid trailing commas, leading to unexpected errors.

<!-- gh-comment-id:2397376330 --> @ninemind commented on GitHub (Oct 7, 2024): The editor does not provide any indication that the resulting JSON is invalid after adding trailing commas. This lack of validation can lead to confusion, as the JSON appears correct but causes issues when sent in a request. Specifically, many APIs reject the request body or fail to process it correctly due to the invalid trailing commas, leading to unexpected errors.
Author
Owner

@yashs33244 commented on GitHub (Oct 7, 2024):

can i solve this issue ..?

<!-- gh-comment-id:2397580743 --> @yashs33244 commented on GitHub (Oct 7, 2024): can i solve this issue ..?
Author
Owner

@adelrodriguez commented on GitHub (Oct 7, 2024):

Can confirm, just ran into this issue as well after updating to the latest version.

<!-- gh-comment-id:2398146392 --> @adelrodriguez commented on GitHub (Oct 7, 2024): Can confirm, just ran into this issue as well after updating to the latest version.
Author
Owner

@Pranay-Pandey commented on GitHub (Oct 8, 2024):

Can this be solved by changing the DEFAULT_OPTIONS for formatting in the file

packages/hoppscotch-common/src/helpers/editor/linting/jsoncPretty.ts

const DEFAULT_OPTIONS: Required<PrettifyOptions> = {
  indent: 2,
  maxLength: 80,
  commentSpace: true,
  trailingComma: true,
}

Why do we have trailingComma as true, instead of false?

<!-- gh-comment-id:2399945224 --> @Pranay-Pandey commented on GitHub (Oct 8, 2024): Can this be solved by changing the DEFAULT_OPTIONS for formatting in the file `packages/hoppscotch-common/src/helpers/editor/linting/jsoncPretty.ts` ``` const DEFAULT_OPTIONS: Required<PrettifyOptions> = { indent: 2, maxLength: 80, commentSpace: true, trailingComma: true, } ``` Why do we have trailingComma as true, instead of false?
Author
Owner

@NayamAmarshe commented on GitHub (Oct 25, 2024):

Please fix this!

<!-- gh-comment-id:2437025021 --> @NayamAmarshe commented on GitHub (Oct 25, 2024): Please fix this!
Author
Owner

@subframe7536 commented on GitHub (Oct 25, 2024):

Please set the default trailingComma to false 🙏

<!-- gh-comment-id:2437227219 --> @subframe7536 commented on GitHub (Oct 25, 2024): Please set the default `trailingComma` to `false` 🙏
Author
Owner

@sscotth commented on GitHub (Oct 26, 2024):

Prettier has a native JSON parser that handles JSON correctly. It can even convert a POJO into a proper JSON object which could improve the current feature by simply using it natively.

image image

JSONC with trailing commas challenges

<!-- gh-comment-id:2439388528 --> @sscotth commented on GitHub (Oct 26, 2024): Prettier has a native JSON parser that handles JSON correctly. It can even convert a POJO into a proper JSON object which could improve the current feature by simply using it natively. <img width="604" alt="image" src="https://github.com/user-attachments/assets/18145a3b-7d78-4c4b-8f0f-f7e4c160852b"> <img width="869" alt="image" src="https://github.com/user-attachments/assets/b7a011e3-2437-43a0-9e08-76b88996b1df"> [JSONC with trailing commas challenges](https://github.com/prettier/prettier/issues/15956)
Author
Owner

@jamesgeorge007 commented on GitHub (Nov 1, 2024):

#4416 released in v2024.10.0.

<!-- gh-comment-id:2452313306 --> @jamesgeorge007 commented on GitHub (Nov 1, 2024): #4416 released in [v2024.10.0](https://github.com/hoppscotch/hoppscotch/releases/tag/2024.10.0).
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hoppscotch#1615
No description provided.