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.

parse single value as array

See original GitHub issue

I was looking for a good query parser including URLSearchParams, query-string and qs. But each is lacking a feature that at least one other has.

Say, I have a query string "a=1" and another "a=1,2". Right now, if I use a comma-separated query parser, then the output would be {a:1} and {a:[1,2]} respectively. But I want my app to get an array regardless; like so {a:[1]} and {a:[1,2]} respectively. Sure, I could handle that in my app itself, but in real-world scenarios, I would likely have many query params; manually handling each one is not ideal, especially for something like this that should be handled by the parser.

In URLSearchParams, it’s possible via getAll function instead of get, but it lacks so many other essential features like having support for comma separated parsing.

It would be great to have an option to force parse certain keys as arrays and not arrays, regardless of the default inferred format; it would be more code friendly rather than having to write exceptions for every little scenario.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:15 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
ljharbcommented, Jun 6, 2022

Went ahead and published v6.10.4.

1reaction
jerrylian-dbcommented, Jun 6, 2022

@ljharb It does! Thanks so much!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Parsing both Array and single object - Stack Overflow
Inside the ReadJson first we get a JToken to be able to determine the read value's Type (kind) · Inside the CanConvert we...
Read more >
Parse Single Value of JSON Array : r/swift - Reddit
I am working with an API which provides a JSON array which is too long to parse every object in reasonable time. However,...
Read more >
How to Parse JSON That Varies Between an Array or a Single ...
How to Parse JSON That Varies Between an Array or a Single Item With Go ... CreateTags will create tags using the provided...
Read more >
Querying Semi-structured Data - Snowflake Documentation
GET accepts a VARIANT, OBJECT, or ARRAY value as the first argument and extracts the VARIANT value of the element in the path...
Read more >
JSON.parse() - JavaScript - MDN Web Docs
The JSON.parse() method parses a JSON string, constructing the JavaScript ... The Object , Array , string, number, boolean, or null value ......
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