From 641942f10869e35bed465a7011fa3b6ef30e6dff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ro=C5=BCek?= Date: Fri, 11 Oct 2019 15:14:51 +0200 Subject: [PATCH] parse function should include properties with empty string as their keys --- src/impl/parser.ts | 2 +- src/test/json.test.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/impl/parser.ts b/src/impl/parser.ts index 12edd80..5ba1c4a 100644 --- a/src/impl/parser.ts +++ b/src/impl/parser.ts @@ -167,7 +167,7 @@ export function parse(text: string, errors: ParseError[] = [], options: ParseOpt function onValue(value: any) { if (Array.isArray(currentParent)) { (currentParent).push(value); - } else if (currentProperty) { + } else if (currentProperty !== null) { currentParent[currentProperty] = value; } } diff --git a/src/test/json.test.ts b/src/test/json.test.ts index a5878f2..846afa5 100644 --- a/src/test/json.test.ts +++ b/src/test/json.test.ts @@ -262,6 +262,7 @@ suite('JSON', () => { assertValidParse('{ "hello": [], "world": {} }', { hello: [], world: {} }); assertValidParse('{ "hello": { "again": { "inside": 5 }, "world": 1 }}', { hello: { again: { inside: 5 }, world: 1 } }); assertValidParse('{ "foo": /*hello*/true }', { foo: true }); + assertValidParse('{ "": true }', { '': true }); }); test('parse: arrays', () => {