query-string
query-string copied to clipboard
Encode empty arrays
For my use case it would be great if there would be a way to encode an empty array as well. For example, in bracket style, maybe {a: []} could be encoded as a[] only (while {a: [1]} is encoded as a[]=1).
See my answer in https://github.com/sindresorhus/query-string/issues/228#issuecomment-575197530. It applies to this too.
Yes, but bracket style does not help here (which is your suggestion there).
So bracket style is less ambiguous, so adding a[] would solve this only ambiguous I know of which still exists for this style.
That style is already used for null values: https://github.com/sindresorhus/query-string/blob/db66e68fc7e323995de713c38504a192472038fa/test/stringify.js#L117
I am tempted to say that null should not be included and use x[] to mean empty array. That would be a breaking change though, so probably better as an opt-in.
I think bar[]= should be an empty array, while bar should be null, bar=null is string null, and bar= is empty string.