oRPC
background

Bracket Notation

Express structured data with bracket notation.

Note: This feature not supported when using JSON Because JSON has its own way to express structured data.

Object

const form = new FormData()
form.append('user[name]', 'John Doe')
form.append('user[age]', '30')
 
const params = new URLSearchParams()
params.append('user[name]', 'John Doe')
params.append('user[age]', '30')
 
// is equivalent to
 
const data = {
    user: {
        name: 'John Doe',
        age: '30'
    }
}

Array

const form = new FormData()
form.append('ids[]', '1')
form.append('ids[]', '2')
 
const params = new URLSearchParams()
params.append('ids[]', '1')
params.append('ids[]', '2')
 
// is equivalent to
 
const data = {
    ids: ['1', '2']
}

On this page