diff --git a/packages/parsing/src/parse-as-json.test.ts b/packages/parsing/src/parse-as-json.test.ts index a6b10ca0..d8f3f19d 100644 --- a/packages/parsing/src/parse-as-json.test.ts +++ b/packages/parsing/src/parse-as-json.test.ts @@ -61,6 +61,7 @@ describe('@acusti/parsing', () => { 'detects an object key with a missing value and fills it in', missingValuesTestCase, ); + it('handles nested arrays without issue', nestedArraysTestCase); }); }); @@ -779,3 +780,32 @@ function missingValuesTestCase() { ], }); } + +function nestedArraysTestCase() { + const response = `{"heading": "Registration Form", "items": [{"heading": "Personal Information", "fields": [{"label": "Name", "name": "name", "type": "text", "placeholder": "Enter your name"}, {"label": "Gender", "name": "gender", "type": "select", "options": ["Male", "Female", "Other"], "placeholder": "Select your gender"}]}], "button": "Next: Security Details"}]}<|im_end|>`; + + expect(parseAsJSON(response)).toEqual({ + heading: 'Registration Form', + items: [ + { + heading: 'Personal Information', + fields: [ + { + label: 'Name', + name: 'name', + placeholder: 'Enter your name', + type: 'text', + }, + { + label: 'Gender', + name: 'gender', + type: 'select', + options: ['Male', 'Female', 'Other'], + placeholder: 'Select your gender', + }, + ], + }, + ], + button: 'Next: Security Details', + }); +}