json-restructure
Version:
A TypeScript library for repairing malformed JSON strings
23 lines • 1.19 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const jsonRepair_1 = require("../../src/utils/jsonRepair");
describe('repairJson', () => {
it('should repair and return a valid JSON string for malformed JSON with single-line comments', () => {
const malformedJson = '{"name":"John","age":30,}//Trailing comma';
const expectedJson = '{"name":"John","age":30}';
const result = (0, jsonRepair_1.repairJson)(malformedJson);
expect(result).toBe(expectedJson);
});
it('should repair and return a valid JSON string for malformed JSON with multi-line comments', () => {
const malformedJson = '{"name":"John","age":30,}/*Trailing comma*/';
const expectedJson = '{"name":"John","age":30}';
const result = (0, jsonRepair_1.repairJson)(malformedJson);
expect(result).toBe(expectedJson);
});
it('should return the original string for valid JSON', () => {
const validJson = '{"name":"John","age":30}';
const result = (0, jsonRepair_1.repairJson)(validJson);
expect(result).toBe(validJson);
});
});
//# sourceMappingURL=jsonRepair.test.js.map
;