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.

Parsing object with array doesn't split a value

See original GitHub issue

Parsing a query string object with parameter that intended to be an array doesn’t split value by comma, while query string in a form of string is parsed correctly.

This is an issue when integrating with frameworks like HAPI that provides query string as a dictionary.

Example

const qs = require('qs');

// Works
console.log(qs.parse('color=a,b', { comma: true }));
// Result: { color: [ 'a', 'b' ] }

// Doesn't work
console.log(qs.parse({ color: 'a,b' }, { comma: true }))
// Result: { color: 'a,b' }
// Expected result as above: { color: [ 'a', 'b' ] }

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
alx630commented, Mar 15, 2020

I have prepared a pull request for this: https://github.com/ljharb/qs/pull/359

0reactions
ljharbcommented, Mar 15, 2020

After some of the discussion in the hapi issue, I think that it’s reasonable that parse with the object form still can split the commas.

Read more comments on GitHub >

github_iconTop Results From Across the Web

splitting json array in javascript not working - Stack Overflow
Parse the JSON string using JSON.parse method and get the property which holds the array. var dates = JSON.parse(respose_data).checkin_date ...
Read more >
JavaScript Split – How to Split a String into an Array in JS
You can invoke the split() method on a string without a splitter/divider. This just means the split() method doesn't have any arguments passed ......
Read more >
String.prototype.split() - JavaScript - MDN Web Docs
returns an array containing one empty string, rather than an empty array. If the string and separator are both empty strings, an empty...
Read more >
Trying to parse a multine array of json objects with logstash ...
But how do I make it so that the array is split into individual log entries? The split function doesn't seem to work,...
Read more >
String.Split Method (System) - Microsoft Learn
Returns a string array that contains the substrings in this instance that are delimited by elements of a specified string or Unicode character...
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