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.

Option to preserve empty arrays and objects at "qs.stringify()"

See original GitHub issue

Documentation saying:

Key with no values (such as an empty object or array) will return nothing

However there are cases when this behavior is not desirable. It brings inconsistencies between stringify and parse methods, meaning same object can’t be stringified and then parsed. Example:

qs.stringify({ foo: [], bar: 1 })
// -> "bar=1"

qs.parse("bar=1")
// -> {bar: "1"}

From above example foo field is lost.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:12
  • Comments:30 (11 by maintainers)

github_iconTop GitHub Comments

10reactions
damonblackcommented, Jun 17, 2020

Seems like sending a query argument that might be empty (like an array of filter fields) is a pretty common use case. I’m fighting with this now.

10reactions
ljharbcommented, May 2, 2020

This is how most backends interpret it - an empty array means there’s nothing there, so there’s nothing lost. Can you elaborate on the use cases?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Remove keys with empty or null values in qs.stringify when ...
I'm constructing a URL with query string parsing qs. stringify in which I want only non-empty or non-null values to be present in...
Read more >
qs | Best of JS
qs allows you to create nested objects within your query strings, by surrounding the name of sub-keys with square brackets [] . For...
Read more >
Node.js querystring.stringify() Method - GeeksforGeeks
It can serialize a single or an array of strings, numbers, and booleans. Any other types of values are coerced to empty strings....
Read more >
qs - npm
Parsing Objects. Qs.parse(string, [options]);. qs allows you to create nested objects within your query strings, by surrounding the name of ...
Read more >
JavaScript JSON stringify() Method - W3Schools
The JSON.stringify() method converts JavaScript objects into strings. When sending data to a web server the data has to be a string.
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