diff --git a/CHANGELOG.md b/CHANGELOG.md index 049fa9228..538950df9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,12 @@ > - :house: [Internal] > - :nail_care: [Polish] +## [Unreleased] + +#### :bug: Bug fix + +- Only paste objects/arrays are JSON.t https://github.com/rescript-lang/rescript-vscode/pull/1148 + ## 1.68.0 #### :rocket: New Feature diff --git a/client/src/commands/paste_as_rescript_json.ts b/client/src/commands/paste_as_rescript_json.ts index cf66e4019..419c139a4 100644 --- a/client/src/commands/paste_as_rescript_json.ts +++ b/client/src/commands/paste_as_rescript_json.ts @@ -11,20 +11,7 @@ const isLikelyJson = (text: string): boolean => { return false; } const first = trimmed[0]; - if (first === "{" || first === "[" || first === '"' || first === "-") { - return true; - } - if (first >= "0" && first <= "9") { - return true; - } - if ( - trimmed.startsWith("true") || - trimmed.startsWith("false") || - trimmed.startsWith("null") - ) { - return true; - } - return false; + return first === "{" || first === "["; }; const ensureFloatString = (value: number): string => { @@ -99,6 +86,10 @@ export const convertPlainTextToJsonT = (text: string): JsonConversionResult => { try { const parsed = JSON.parse(text); + // Only convert objects and arrays, not primitive values + if (typeof parsed !== "object" || parsed === null) { + return { kind: "notJson" }; + } return { kind: "success", formatted: formatJsonValue(parsed) }; } catch { return {