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

Stringifying array escape brackets #388

Open
jagwingchoy opened this issue Dec 28, 2020 · 1 comment
Open

Stringifying array escape brackets #388

jagwingchoy opened this issue Dec 28, 2020 · 1 comment

Comments

@jagwingchoy
Copy link

Hi there! I am using this package for stringifying data before sending requests to the backend.
I recently have a case like below:

let body = { pets: ["has_dog", "has_cat"] };
config.body = qs.stringify(body, { arrayFormat: 'brackets' });
console.log("config body", config.body);

Expected Result

pets[]=has_dog&pets[]=has_cat

Current Result

pets%5B%5D=has_dog&pets%5B%5D=has_cat

Does anyone facing same issue? How you can solve it so that brackets will not be escaped? Thanks.

@ljharb
Copy link
Owner

ljharb commented Dec 28, 2020

Try:

qs.stringify(body, { arrayFormat: 'brackets', encodeValuesOnly: true });

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

No branches or pull requests

2 participants