Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 5 additions & 14 deletions client/src/commands/paste_as_rescript_json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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 {
Expand Down