Option to preserve empty arrays and objects at "qs.stringify()"
See original GitHub issueDocumentation 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:
- Created 3 years ago
- Reactions:12
- Comments:30 (11 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
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?