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

How can you keep the square brackets when using arrayFormat: comma #481

Open
samgermain opened this issue Sep 6, 2023 · 4 comments
Open

Comments

@samgermain
Copy link

With the following code

qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'comma' })
// 'a=b,c'

plus some option, I want to obtain a result that looks like

// 'a=[b,c]'

How can I do this?

@ljharb
Copy link
Owner

ljharb commented Sep 6, 2023

That’s not the comma format, so I’m not sure how you can.

What server expects that format??

@samgermain
Copy link
Author

That’s not the comma format, so I’m not sure how you can.

well it doesn't need to be the comma format then, but it needs to be that format

What server expects that format??

binance

@ljharb
Copy link
Owner

ljharb commented Sep 6, 2023

oof, so binance basically just invented their own format instead of using the universal ones that already exist?

I'm not sure how to do that with qs; perhaps with a custom encoder?

@lzdyes
Copy link

lzdyes commented Nov 21, 2023

You can use filter.

qs.stringify(params, {
  filter: (prefix, value) => {
    if (Array.isArray(value)) return `[${value.join(',')}]`
    return value
  },
})

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

3 participants