qs
qs copied to clipboard
Stringifying array escape brackets
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.
Try:
qs.stringify(body, { arrayFormat: 'brackets', encodeValuesOnly: true });