Comment #12 on issue 34 by tim.schaub: Repeated section should iterate over
dictionaries and have special variables $name and $value
http://code.google.com/p/json-template/issues/detail?id=34
Yeah, sorry, that last example was hastily written.
I was thinking bracket notation, not dot notation:
Object members:
{.repeated key obj}
{key}: {obj[key]}
{.end}
Array elements:
{.repeated index list}
{index}: {list[index]}
{.end}
But, as that is not supported, it doesn't make sense.
If the cursor is the element value for an array and the member value for an
object,
this would read:
Object members:
{.repeated key obj}
{key}: {...@}
{.end}
Array elements:
{.repeated index list}
{index}: {...@}
{.end}
(And if you didn't need a reference to the element index or the member
name, the
optional middle term could be omitted.)
I agree that what you typically want when iterating over an array is the
element
value. The free "section" term just looked to me like a place to assign
the index
while you were at it. And the cursor would assume the element value. For
objects,
cursor would assume the member value (as you also suggest). And I was
suggesting
that the space currently occupied by "section" (in .repeated section) could
be a
place for the member name.
I'll stop being hung up on it now. I am happy you're considering iterating
over
object members now. I still think you could get away with only
reserving "@" (or
less) but I won't push it.
PS - In terms of valid identifiers, I wasn't referring to JavaScript or any
other
language that might be used in an implementation. I was referring to
JSON. "@name"
and "$name" are equally valid member names. And, in JS, the following is
perfectly
legitimate:
>>> var o = {"@name": "value"}
>>> o["@name"]
"value"
I was thinking about how much care application developers have to put into
ensuring
that the data they pass to the template doesn't contain member names that
are
reserved by the language. A JDIL (http://jdil.org/) structure will likely
have
member names like "@value". A data structure using JSON referencing will
have member
names like "$ref". The more member names you reserve for this language,
the more
work people have to do to structure their data accordingly. In my mind, a
nice JSON
templating language could be used with any valid JSON.
--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "JSON
Template" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/json-template?hl=en
-~----------~----~----~----~------~----~------~--~---