-
Notifications
You must be signed in to change notification settings - Fork 7
Description
The bracket notation is unquoted which means restricted characters are unavailable and numerals can not be used as JSON names. The JSON spec is flexible in this regard so it would be preferred if HTML JSON encoding can produce the full range of allowed JSON names to avoid creating a subset of JSON encoding.
To remedy this, the bracket notation can be updated to allow a quotation syntax using either single or double quotation marks for non-numeric values. The values within the quotations can be escaped using the backslash character to allow restricted characters. Numerical names can be quoted to avoid creating sparse arrays.
To retain the conciseness of simple names, the addition of "dot notation" would allow for deep object structures to be created concisely. For the set of allowed dot notation first characters it would be preferable to use the javascript syntax rules for uniformity with javascript property accessors.
Note that HTML entity resolution has to be resolved prior to the JSON name parsing and the entities need to be escaped if they resolve to a restricted character which would break the name parsing algorithm. The final stage would be to encode the name as a JSON string with escaping as necessary.
The set of restricted characters for the quoted JSON name should be the same as the JSON specification with the explicit inclusion of the single quote character to allow for the flexibility of HTML quotation characters. This character should be unescaped during encoding to conform exactly with the JSON specification and ensure interoperability with all JSON implementations.
Examples:
<input name="object['abc']">
{ "object" : { "abc": "" } }
<input name="object['123']">
{ "object" : { "123": "" } }
<input name="object['abc[]']">
{ "object" : { "abc[]": "" } }
<input name="object['abc\\']">
{ "object" : { "abc\\": "" } }
<input name="object['abc\'']">
{ "object" : { "abc'": "" } }
<input name="object["abc\""]">
{ "object" : { "abc\"": "" } }
<input name="object['abc"']">
{ "object" : { "abc\"": "" } }
<input name="object['abc\\"']">
{ "object" : { "abc\\\"": "" } }
<input name="object['abc\u0022']">
{ "object" : { "abc\u0022": "" } }
<input name="object['abc\\u0022']">
{ "object" : { "abc\\u0022": "" } }
<input name="wow.such.deep[3].much.power['!']">
{
"wow": {
"such": {
"deep": [
null
, null
, null
, {
"much": {
"power": {
"!": "Amaze"
}
}
}
]
}
}
}