Skip to content

Commit a377ab7

Browse files
committed
Merge branch 'main' of https://github.com/timheuer/jsondbg
2 parents beed295 + b818af7 commit a377ab7

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/jsonViewer.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ function isLikelyJson(str: string): { isLikely: boolean, reason?: string } {
1414
if (!str) {
1515
return { isLikely: false, reason: 'Empty string is not valid JSON' };
1616
}
17+
18+
// Strip quotation
19+
if ((str.startsWith('"') && str.endsWith('"')) || str.startsWith("'") && str.endsWith("'")) {
20+
str = str.slice(1, -1);
21+
}
22+
23+
// Trim
24+
str = str.trim();
1725

1826
// Check if the string starts with either { or [ which are valid JSON starters
1927
if (!(str.startsWith('{') || str.startsWith('['))) {
@@ -85,7 +93,7 @@ function isLikelyJson(str: string): { isLikely: boolean, reason?: string } {
8593
*/
8694
function preprocessJsonString(jsonValue: string): string {
8795
// If the value is enclosed in quotes (string representation), remove them
88-
if (jsonValue.startsWith('"') && jsonValue.endsWith('"')) {
96+
if ((jsonValue.startsWith('"') && jsonValue.endsWith('"')) || (jsonValue.startsWith("'") && jsonValue.endsWith("'"))) {
8997
jsonValue = jsonValue.substring(1, jsonValue.length - 1);
9098
// Unescape any escaped quotes
9199
jsonValue = jsonValue.replace(/\\"/g, '"');

0 commit comments

Comments
 (0)