6 ms·
the only problem with the bracket syntax is when it comes to nested things <form enctype='application/json'> <input name='wow[such][deep][3][
by hayksaakian 12y ago
the only problem with the bracket syntax is when it comes to nested things
<form enctype='application/json'>
<input name='wow[such][deep][3][much][power][!]' value='Amaze'>
</form>
// produces
{
"wow": {
"such": {
"deep": [
null
, null
, null
, {
"much": {
"power": {
"!": "Amaze"
}
}
}
]
}
}
}
- joesb 12y agoWhat's the problem with that? If it's deeply nested, then it's deeply nested, no matter what.
- byuu 12y agoIt's pedantic, but it's a tad clunky now: I'd use something like "wow/such/deep[3]/much/power/!" to differentiate child nodes from array indexes, and also strongly advise against a node named "!" on principle. Of course then you'd say "but I want '/' in my node name!", and then you get to bikeshed an escape sequence, but you'd need that anyway for a node name with '[' or ']' in it. However, what they've done is workable if all the browser vendors implement it.
- stephenr 12y agosquare brackets are a reasonably common way to access data in an hash-like object. both Javascript (objects) and PHP (associative arrays) use/allow square brackets for this.