Skip to content

Commit 4e11d09

Browse files
committed
Updated to parse jsonstring with JSON.parse
1 parent 9eac3da commit 4e11d09

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

src/document/Document.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { LoggerFactory } from '../telemetry/LoggerFactory';
44
import { detectCfnFileType } from './CloudFormationDetection';
55
import { DocumentMetadata } from './DocumentProtocol';
66
import { detectDocumentType, uriToPath } from './DocumentUtils';
7-
import { parseJson } from './JsonParser';
87
import { parseValidYaml } from './YamlParser';
98

109
export class Document {
@@ -42,7 +41,7 @@ export class Document {
4241

4342
public getParsedDocumentContent(): unknown {
4443
if (this.documentType === DocumentType.JSON) {
45-
return parseJson(this.contents());
44+
return JSON.parse(this.contents());
4645
}
4746
return parseValidYaml(this.contents());
4847
}

tst/unit/document/Document.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,12 @@ describe('Document', () => {
147147
});
148148
});
149149

150-
it('should handle invalid JSON gracefully', () => {
150+
it('should throw for invalid JSON', () => {
151151
const content = '{"invalid": json}';
152152
const textDocument = TextDocument.create('file:///test.json', 'json', 1, content);
153153
const doc = new Document(textDocument);
154154

155-
const result = doc.getParsedDocumentContent();
156-
expect(result).toBeDefined();
155+
expect(() => doc.getParsedDocumentContent()).toThrow();
157156
});
158157

159158
it('should throw for invalid YAML', () => {

0 commit comments

Comments
 (0)