Skip to content

Feature: Add JSON Repair operation with comprehensive malformed JSON fixing capabilities #2087

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

maojunxyz
Copy link

Summary

Adds a new JSON Repair operation that fixes common JSON formatting issues using the jsonrepair library.

Changes

  • New operation: JSON Repair in Code category
  • Fixes missing quotes, commas, trailing commas, comments, and other common JSON issues
  • Uses jsonrepair library (v3.13.0) for reliable repair functionality
  • Includes 12 test cases covering various repair scenarios

Files changed

  • src/core/operations/JSONRepair.mjs - Main operation
  • tests/operations/tests/JSONRepair.mjs - Test suite
  • src/core/config/Categories.json - Category configuration
  • tests/operations/index.mjs - Test registration
  • package.json - Added jsonrepair dependency

Testing

Done.
Running Node API tests...
Tests completed ████████████████████████████████████████ 217/217 | 100% | Duration: 1s

TOTAL 217
PASSING 217

Running operation tests...
Tests completed ████████████████████████████████████████ 1728/1728 | 100% | Duration: 6s

TOTAL 1728
PASSING 1728
All tests pass (1728/1728). New operation includes comprehensive test coverage for:

  • Missing quotes around keys
  • Single/double quote conversion
  • Trailing and missing commas
  • Python constants (True/False/None)
  • Comments removal
  • JSONP notation handling

Addresses common user need for fixing malformed JSON data.

- Add new JSON Repair operation using jsonrepair library (v3.13.0)
- Support for fixing common JSON issues:
  * Missing quotes around object keys
  * Single quotes to double quotes conversion
  * Trailing commas removal
  * Missing commas insertion
  * Python constants (True/False/None) to JSON equivalents
  * Comments removal (both // and /* */ styles)
  * JSONP notation handling
- Include comprehensive test suite with 11 test cases
- Add operation to 'Code tidy' category
- Follows KISS principle with minimal configuration
- Uses dynamic import for robust module loading

Resolves the common issue of repairing malformed JSON data,
particularly useful for processing JSON with missing commas
between object properties.

Author: maojunxyz <maojun@linux.com>
- Add test case to verify JSONP callback wrapper removal
- Validates that callback({name: John, age: 30}) becomes {name: John, age: 30}
- Ensures comprehensive coverage of jsonrepair library features
- Total test cases now: 12 (previously 11)
@CLAassistant
Copy link

CLAassistant commented Aug 8, 2025

CLA assistant check
All committers have signed the CLA.

- Fix trailing spaces in JSONRepair.mjs
- Convert single quotes to double quotes in test files
- Fix line ending style (CRLF to LF)
- All lint checks now pass
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 this pull request may close these issues.

2 participants