ljharb/qs

Stringify with "arrayFormat: comma" encodes objects inside arrays as "[object Object]"

Ouverte

#378 ouverte le 11 août 2020

 (30 commentaires) (6 réactions) (0 personne assignée)JavaScript (904 forks)batch import
bughelp wantedstringify

Métriques du dépôt

Stars
 (8 943 étoiles)
Métriques de merge PR
 (Merge moyen 6j 22h) (2 PRs mergées en 30 j)

Description

Tested on version 6.9.4

Stringify with arrayFormat: comma encodes objects inside arrays as [object Object]

I took this code from the examples:

qs.stringify({ a: { b: { c: 'd', e: 'f' } } });
// 'a[b][c]=d&a[b][e]=f'

and added an array around the inside object

qs.stringify({ a: { b: [{ c: 'd', e: 'f' }] } }, { encode: false, arrayFormat: 'comma' })
// 'a[b]=[object Object]'

The inside data is lost this way.

I tried the allowDots setting too, but that didn't fix anything.

I'm not sure what the output should be like exactly, but this is unusable right now. In my project I did Array.map(p => ${p.ID}::${p.Value}), but that's very specific and I'm unsure if the :: is a good seperator.

Guide contributeur