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.

Does Not Parse Boolean/Number in array

See original GitHub issue

Consider this code

Qs.stringify({
  field: {
      $in: [true, false,0,1]
  }
})

true, false, 0, 1 all become strings

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
ljharbcommented, Aug 27, 2021

parse is expected to produce something that’s not a string, but stringify is not.

Separately, qs.parse does not in fact do that in my testing:

qs.parse('true') // { true: '' }
qs.parse('a=true') // { a: 'true' }

etc.

0reactions
ljharbcommented, Sep 15, 2021

@dmitry that’s because parse only accepts a string. Passing a boolean in is a type error, something that I’ll probably make throw an exception in the next semver-major, whenever that is.

Regarding #91, a=true in a query string is the string “true”, not a boolean, so qs won’t ever do the wrong thing there by default. You’ll have to use a custom decoder if you want nonstandard types.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Boolean.parseBoolean not working - Stack Overflow
When I read the array the string array (parts) says that parts[0]=true;. ,but when I use Boolean.parseBoolean array[0] is still false.
Read more >
2 Ways to Convert Values to Boolean in JavaScript
The first ! coerce the value to a boolean and inverse it. In this case, !value will return false . So to reverse...
Read more >
JSON.stringify() - JavaScript - MDN Web Docs
A function that alters the behavior of the stringification process, or an array of strings and numbers that specifies properties of value to...
Read more >
Convert.ToBoolean Method (System) - Microsoft Learn
Returns the specified Boolean value; no actual conversion is performed. ... The following example converts an array of SByte values to Boolean values....
Read more >
Types – Liquid template language - Shopify
String; Number; Boolean; Nil; Array; EmptyDrop. You can initialize Liquid variables ... Liquid does not convert escape sequences into special characters.
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