question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ArrayFormat Type Comma is producing the output of Array Format Repeat when the array length is 1

See original GitHub issue

qs.stringify({ a: ['b'] }, { arrayFormat: 'comma' }) should return the a=b.

But it is returning the repeat type format - a%5B%5D=b ~ a[]=b

Below is the documentation and expected behaviour from readme

qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'indices' })
// 'a[0]=b&a[1]=c'
qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'brackets' })
// 'a[]=b&a[]=c'
qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'repeat' })
// 'a=b&a=c'
qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'comma' })
// 'a=b,c'

Below is the screenshot for the same

image

Can anyone help me if this is an issue or Am I missing something?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
mima0815commented, Jun 10, 2022

we run into the same issue with the new version.

not all APIs we are using are capable to handling query strings with brackets, they are expecting comma separated lists in all cases or no comma if it is only one value.

+1 for the additional option to toggle the “Arrayness” feature.

5reactions
manoj-rpcommented, Jun 10, 2022

I have read the thread. But Shouldn’t it be configurable?

Can we have another option along with arrayType.

preserveArrayness: true/false

Because there can be usecases like

One can use qs for stringifying it and may not be using it for parsing back again?

In our case,

We stringify it and pass the query string to an external service and that service doesn’t use the qs module to parse it back?

Any thoughts @ljharb

Read more comments on GitHub >

github_iconTop Results From Across the Web

Stringify with `comma` format should add square brackets to ...
Hi. With new comma array format, stringify of array with single value will produce following result: const options = { arrayFormat: 'comma' } ......
Read more >
How to correctly use axios params with arrays - Stack Overflow
YOUR_ARRAY.length - 1) params += '&'; }. And then make the request like so: ... In React I needed to use axios with...
Read more >
Trailing commas - JavaScript - MDN Web Docs
JavaScript allows trailing commas wherever a comma-separated list of values is accepted and more values may be expected after the last item.
Read more >
MATLAB repmat - Repeat copies of array - MathWorks
This MATLAB function returns an array containing n copies of A in the row and column dimensions.
Read more >
Work with arrays | BigQuery - Google Cloud
In Google Standard SQL for BigQuery, an array is an ordered list consisting of zero or more values of the same data type....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found