Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encode empty arrays #231

Open
mitar opened this issue Jan 6, 2020 · 4 comments
Open

Encode empty arrays #231

mitar opened this issue Jan 6, 2020 · 4 comments

Comments

@mitar
Copy link

mitar commented Jan 6, 2020

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).

@sindresorhus
Copy link
Owner

See my answer in #228 (comment). It applies to this too.

@mitar
Copy link
Author

mitar commented Jan 16, 2020

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.

@sindresorhus
Copy link
Owner

sindresorhus commented Feb 2, 2020

That style is already used for null values:

}), 'bar[]&foo[]=a&foo[]&foo[]=');

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.

@mitar
Copy link
Author

mitar commented Feb 2, 2020

I think bar[]= should be an empty array, while bar should be null, bar=null is string null, and bar= is empty string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants