diff --git a/src/jsonify/parse.ts b/src/jsonify/parse.ts index 66ed83ca89c..03859467228 100644 --- a/src/jsonify/parse.ts +++ b/src/jsonify/parse.ts @@ -30,9 +30,13 @@ function unpack( custom: CustomParser | undefined, ): void { if (idx in hydrated) return; - + const current = arr[idx]; if (typeof current === "number") { + if(idx !== 0) { + hydrated[idx] = current; + return; + } switch (current) { case UNDEFINED: hydrated[idx] = undefined; @@ -149,8 +153,8 @@ function unpack( hydrated[idx] = actual; const keys = Object.keys(current); - for (let i = 0; i < keys.length; i++) { - const key = keys[i]; + for (const element of keys) { + const key = element; // deno-lint-ignore no-explicit-any const ref = (current as any)[key]; if (ref < 0) { diff --git a/src/jsonify/parse_test.ts b/src/jsonify/parse_test.ts index 8e5a1b88df1..42b17f1cbf3 100644 --- a/src/jsonify/parse_test.ts +++ b/src/jsonify/parse_test.ts @@ -97,3 +97,7 @@ Deno.test("parse - circular references", () => { Deno.test("parse - object", () => { expect(parse('[{"foo":1},42]')).toEqual({ foo: 42 }); }); + +Deno.test("parse - object with number negative", () => { + expect(parse('[{"foo":1}, -1]')).toEqual({ foo: -1 }); +});