You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use queryst library to parse query-string to corresponding json values.
use queryst::parse;// will contain result as Json valuelet object = parse("foo[0][a]=a&foo[0][b]=b&foo[1][a]=aa&foo[1][b]=bb");
Description
queryst allows you to create nested objects within your query strings,
by surrounding the name of sub-keys with square brackets [].
or example, the string 'foo[bar]=baz' converts to this JSON:
{
"foo": {
"bar": "baz"
}
}
URI encoded strings work too:
parse('a%5Bb%5D=c');// { "a": { "b": "c" }}
You can also nest your objects, like 'foo[bar][baz]=foobarbaz':
{"foo": {"bar": {"baz": "foobarbaz"}}}
Parsing Arrays
queryst can also parse arrays using a similar [] notation:
parse('a[]=b&a[]=c');// { "a": ["b", "c"] }
You may specify an index as well:
parse('a[0]=c&a[1]=b');// { "a": ["c", "b"] }
Note that the only difference between an index in an array and a key in an object is that the value between the brackets must be a number to create an array.
querystdoes't allow to specify sparse indexes on arrays and will convert target array to object: