V
V
Vladimir T.2016-04-06 18:25:00
JavaScript
Vladimir T., 2016-04-06 18:25:00

Which module can convert json to querystring?

There is json:

{
    phone: [ '1111111', '2222222222' ]
}

I want to turn it into a querystring like phone=1111111&phone=2222222222. Tried https://www.npmjs.com/package/qs but it returns phone%5B0%5D=1111111&phone%5B1%5D=2222222222 like this.
Question - is there a ready-made module that can normally convert json with a nested array into a sane querystring?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Immortal_pony, 2016-04-06
@Immortal_pony

The module you specified returns a perfectly valid string.
As for your example, it is wrong:
If you cast this string to an array, you get
... because there are two parameters in the string with the same name.
If you are confused by the percentages in the line, then these are encoded square brackets. You can decode using the decodeuricomponent function

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question