Hey, thanks for the suggestion.  This has crossed my mind, but so far
no one else has brought it up.  How about giving the keys and values
special names, e.g. treat it as a 2 element object with "name" and
"value" fields, like:

List:
{.repeated section pages}
  {name} {value.url}
{.end}

Page 0 URL: {page0.url}

-->

List:
zero foo
one bar

Page 0 Url: bar

It would have to work with nested dictionaries too.

> If this is something that is not already handled in a different way, I
> think it could be implemented in a mostly backwards compatible way
> (breaking where templates use substitution for a variable named "section").
>
> If this email doesn't make any sense, I could rephrase it by starting
> with the collapsed data dictionary and asking "how can I create a list
> of links from this (and allow for deep linking without data duplication)?"

It make sense, and can be done without breaking compatibility, since
repeated sections only take lists now.

But in general, JSON Template can't handle arbitrary JSON.  It's
supposed to be JSON you craft for the template specifically.

For example, it doesn't handle JSON where a: 1 or a: [1, 2] -- the
JSON has to be transformed so the value is always a list.

To do this within the existing system, I would write a function that
annotates the data dictionary.  Say you get a bunch of rows of URLs
from a database.

rows:

(zero, foo)
(one, bar)

Now I would write a function to turn that into JSON:

{
  pages-list: [{
            "title": "zero",
            "url": "foo"
        }, {
            "title": "one",
            "url": "bar"
        }],
  "zero": "foo",
  "one": "bar"
}

So to play devil's advocate, there's no real duplication there.  It's
just some transformations in the code, which you always need anyway.
I think I would have to see an actual example of this.  Is it
something you really ran into?

Andy

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to