[PR #4416] [MERGED] fix: trailing comma makes json invalid #4787

Closed
opened 2026-03-17 02:17:35 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/hoppscotch/hoppscotch/pull/4416
Author: @anwarulislam
Created: 10/8/2024
Status: Merged
Merged: 10/28/2024
Merged by: @AndrewBastin

Base: nextHead: hotfix/jsonc-invalid-issue


📝 Commits (7)

  • 2b431af fix: trailing comma issue makes json invalid
  • f837704 chore: remove trailing commas on prettify
  • 887a126 fix: jsonc prettifier
  • 0183d52 fix: strip comments and trailing comma by walking the AST
  • 4daa7d9 fix: prevent exceptions when incoming node doesn't have adequate info
  • eeb676c fix: ensure invalid JSON request body contents are sent along
  • 641d6fb refactor: keep the node conversion functions pure

📊 Changes

5 files changed (+93 additions, -266 deletions)

View changed files

📝 packages/hoppscotch-common/src/components/environments/my/Details.vue (+2 -2)
📝 packages/hoppscotch-common/src/components/environments/teams/Details.vue (+2 -2)
📝 packages/hoppscotch-common/src/helpers/editor/linting/jsonc.ts (+79 -4)
📝 packages/hoppscotch-common/src/helpers/editor/linting/jsoncPretty.ts (+7 -255)
📝 packages/hoppscotch-common/src/helpers/utils/EffectiveURL.ts (+3 -3)

📄 Description

Closes #4411

What's changed

This pull request fixes an issue where a trailing comma in a JSON object was causing the JSON to be invalid when we send it to the server. This was leading to errors when the JSON was being parsed.

The fix involves removing the trailing comma before sending it to the server, ensuring the JSON is correctly formatted and valid before proceeding request.

You may still have comments and trailing commas in your json body. That won't invalidate json because comments and trailing commas being stripped out before sending the request.

  • Not Completed
  • Completed

Notes to reviewers

Examples JSON body

{
  // https://hello.com/
  "id": "https://hello.com",
  "value": {
    "num": 2,
  },
}

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/hoppscotch/hoppscotch/pull/4416 **Author:** [@anwarulislam](https://github.com/anwarulislam) **Created:** 10/8/2024 **Status:** ✅ Merged **Merged:** 10/28/2024 **Merged by:** [@AndrewBastin](https://github.com/AndrewBastin) **Base:** `next` ← **Head:** `hotfix/jsonc-invalid-issue` --- ### 📝 Commits (7) - [`2b431af`](https://github.com/hoppscotch/hoppscotch/commit/2b431afcfc599661d51098b094158123b775c6e4) fix: trailing comma issue makes json invalid - [`f837704`](https://github.com/hoppscotch/hoppscotch/commit/f837704e9963b3e9221fdcc931854324903ab1fa) chore: remove trailing commas on prettify - [`887a126`](https://github.com/hoppscotch/hoppscotch/commit/887a1260a91fc1e59381a3a96028265c27278d74) fix: jsonc prettifier - [`0183d52`](https://github.com/hoppscotch/hoppscotch/commit/0183d52b9d6a7dafd3a17141e1fa9d699f9cf28e) fix: strip comments and trailing comma by walking the AST - [`4daa7d9`](https://github.com/hoppscotch/hoppscotch/commit/4daa7d9feff2cede4100c7c68e52f60ce17286f8) fix: prevent exceptions when incoming node doesn't have adequate info - [`eeb676c`](https://github.com/hoppscotch/hoppscotch/commit/eeb676cc19876985c10fd116d9fd3bbf2ae45a3b) fix: ensure invalid JSON request body contents are sent along - [`641d6fb`](https://github.com/hoppscotch/hoppscotch/commit/641d6fb7bd6950d90568f5ddc15d5d0d823d52a9) refactor: keep the node conversion functions pure ### 📊 Changes **5 files changed** (+93 additions, -266 deletions) <details> <summary>View changed files</summary> 📝 `packages/hoppscotch-common/src/components/environments/my/Details.vue` (+2 -2) 📝 `packages/hoppscotch-common/src/components/environments/teams/Details.vue` (+2 -2) 📝 `packages/hoppscotch-common/src/helpers/editor/linting/jsonc.ts` (+79 -4) 📝 `packages/hoppscotch-common/src/helpers/editor/linting/jsoncPretty.ts` (+7 -255) 📝 `packages/hoppscotch-common/src/helpers/utils/EffectiveURL.ts` (+3 -3) </details> ### 📄 Description Closes #4411 ### What's changed This pull request fixes an issue where a trailing comma in a JSON object was causing the JSON to be invalid when we send it to the server. This was leading to errors when the JSON was being parsed. The fix involves removing the trailing comma before sending it to the server, ensuring the JSON is correctly formatted and valid before proceeding request. You may still have comments and trailing commas in your json body. That won't invalidate json because comments and trailing commas being stripped out before sending the request. - [ ] Not Completed - [x] Completed ### Notes to reviewers #### Examples JSON body ```jsonc { // https://hello.com/ "id": "https://hello.com", "value": { "num": 2, }, } ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-17 02:17:35 +03:00
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#4787
No description provided.