Query String ↔ JSON
Read a query string as JSON and build one back from an object.
Result
Good to know
- A leading ? or # is ignored, so you can paste the tail of a URL as it stands.
- A key that appears more than once becomes an array, and so does one written as tag[]. A key written as filter[colour] becomes a nested object.
- Everything read from a query string is text. A query string carries no types, so 2 arrives as "2".
- Going the other way the brackets come back percent-encoded, which is the correct spelling for a URL even though many servers accept them bare.
25 views