URL search parameters after the "?" in a URL form the overall hash structure of the JSON object [1] sent to the server.
Key/value
Keys and values form a pair as a way to reference data. Each key/value pair in the search parameters is separated by an "&". The key is the text value to the left of the "=", and the "value" is the text value to the right of the "=" and may be "%" URL encoded [2].
URL parameters
[code]
limit=100&page=1
[/code]
JSON object
[code]
{
"limit": 100,
"page": 1
}
[/code]
Sub-hash
Sub-hashes are supported by using square brackets "[ ]". The text value inside the square brackets is the sub key that the value will be added to.
Single-level example
URL parameters
[code]
search[name]=test&search[order]=id&limit=20
[/code]
JSON object
[code]
{
"search": {
"name": "test",
"order": "id",
},
"limit": 20
}
[/code]
Multi-level example
Sub-hashes can form deeper sub-hashes by stacking the "[ ]" terms in a row.
URL parameters
[code]
search[user][id]=1
[/code]
JSON object
[code]
{
"search": {
"user": {
"id": 1
}
}
}
[/code]
Array
Arrays can be sent by appending an empty "[]" at the end of the final specifier for the key.
Single-item example
URL parameters
[code]
search[name][]=test
[/code]
JSON object
[code]
{
"search": {
"name": ["test"]
}
}
[/code]
Multi-item example
Multiple array items are sent by using the exact same key for each value in the array.
URL parameters
[code]
search[id][]=1&search[id][]=2
[/code]
JSON object
[code]
{
"search": {
"id": [1, 2]
}
}
[/code]
Array of files
When sending an array of files, the parameter follows a similar format, although it is treated like a hash, where each key of the hash is the index of the file in the array, starting with 0. Since files require a multi-part format, it will look like something similar to the following.
[code]
--9cab1cceecb6c4f5634bcba0e89ee77c
Content-Disposition: form-data; name="upload[files][0]"; filename="6fe571c9df2912b1ae551045c2157240.jpg"
Content-Type: image/jpeg
<FILE DATA>
[/code]
See also
External links
[1] https://www.w3resource.com/JSON/structures.php
[2] https://www.w3schools.com/tags/ref_urlencode.ASP