ljharb / qs

A querystring parser with nesting support
BSD 3-Clause "New" or "Revised" License
8.5k stars 729 forks source link

nested json was stringified into wrong format using square brackets #417

Closed t238wang closed 3 years ago

t238wang commented 3 years ago

Hi, I tried to stringify this json with qs.stringify(data, { arrayFormat: 'brackets' } and data is {data: {generatedTime: value}}

the result is data[generatedTime]=value instead of data=%7B%22generatedTime%22%3A%221626959827266%22%7D does anyone know what might be wrong?

t238wang commented 3 years ago

when parse it back, the difference is between a json string and a json object.

ljharb commented 3 years ago

JSON is only ever a string; once it’s an object it’s not JSON anymore.

The encoding of the brackets and equals sign should not impact the parsing, are not required, but you can pass options to stringify if that’s what you want for some reason.