ljharb/qs

Arrays parsed incorrectly

Open

#288 opened on Nov 27, 2018

View on GitHub
 (3 comments) (3 reactions) (0 assignees)JavaScript (744 forks)batch import
feature requesthelp wantedparse

Repository metrics

Stars
 (8,015 stars)
PR merge metrics
 (Avg merge 6d 22h) (2 merged PRs in 30d)

Description

Hi, I have this object:

const filter = {
  3: [{ name: 'Test', id: 50753 }, { name: 'Test2', id: 48464 }],
  6: ['2018-11-01', '2018-11-02']
}

I call stringify and parse

const stringifyQuery = Qs.stringify(filter, { arrayFormat: 'brackets' })
const parseQuery = Qs.parse(stringifyQuery, { arrayLimit: 0 })

Result parse: Key '3' contains only 1 element instead of 2. And this element contains the merged keys name, id:

3: Array(1)
  0:
    id: (2) ["50753", "48464"]
    name: (2) ["Test", "Test2"]

I expect:

3: Array(2)
  0: {name: "Test", id: 50753}
  1: {name: "Test2", id: 48464}

Please help me https://codepen.io/anon/pen/rQrqXx

Contributor guide