diff --git a/cli/script.ts b/cli/script.ts index 463e5b5bd3..bf2e276bb9 100644 --- a/cli/script.ts +++ b/cli/script.ts @@ -180,24 +180,28 @@ export async function resolve(inputs: string[]): Promise> { } for (const input of inputs) { - let jsonObj; + let data: string; if (input.startsWith("@")) { - let data: string; if (input == "@-") { data = new TextDecoder().decode(await readAll(Deno.stdin)); } else { data = await Deno.readTextFile(input.substring(1)); } - jsonObj = JSON.parse(data); } else { if (input.startsWith("{")) { - jsonObj = JSON.parse(input); + data = input; } else { const key = input.split("=", 1)[0]; const value = JSON.parse(input.substring(key.length + 1)); - jsonObj = Object.fromEntries([[key, value]]); + data = JSON.stringify(Object.fromEntries([[key, value]])); } } + let jsonObj; + try { + jsonObj = JSON.parse(data); + } catch { + jsonObj = data; + } result = { ...result, ...jsonObj }; } return result;