Discussion:
parent property value, navigating context stack
peg
2010-02-18 15:17:16 UTC
Permalink
Hi,

I wanted to get a parent property value that exists in the current
context:
{
id: "parentId",
...
child: { id: "childId", ... }
}

and produce in a template

{.section child }
child id: {id} parentId: {?}
{.end}

perhaps a specific sign 'a la ' xpath could be used to indicate parent
navigation:

../id or ^id

don't know.

Or it could be done by formatter accessing the current context, but
need then a way to get parent's context ...

It could be done (in the code) the same way the {@index} is
treated ...
that's where I put it for my needs for now

Phil
--
You received this message because you are subscribed to the Google Groups "JSON Template" group.
To post to this group, send email to json-template-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to json-template+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit this group at http://groups.google.com/group/json-template?hl=en.
Andy Chu
2010-02-22 00:38:25 UTC
Permalink
Right now there is no way to do this unfortunately. Please feel free
to file a bug report and I'll have to think about how to best support
it.

I think someone wanted the opposite too. They wanted @.foo to stop
the searching up the stack.

I guess I wasn't thinking that these name conflicts would be very
common. Can you just rename your fields?

Andy
Post by peg
Hi,
I wanted to get a parent property value that exists in the current
{
   id: "parentId",
   ...
   child: { id: "childId", ... }
}
and produce in a template
{.section child }
  child id: {id} parentId: {?}
{.end}
perhaps a specific sign 'a la ' xpath could be used to indicate parent
../id or ^id
don't know.
Or it could be done by formatter accessing the current context, but
need then a way to get parent's context ...
treated ...
that's where I put  it for my needs for now
Phil
--
You received this message because you are subscribed to the Google Groups "JSON Template" group.
For more options, visit this group at http://groups.google.com/group/json-template?hl=en.
--
You received this message because you are subscribed to the Google Groups "JSON Template" group.
To post to this group, send email to json-template-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to json-template+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/json-template?hl=en.
peg
2010-02-22 08:08:30 UTC
Permalink
Of course if you are producer of json datas you can change all
properties name ... even if that's not so easy when json is produced
from beans that you can't change easily.

Anyway, the more general question is : do we need xpath like
expression to navigate in json data structure (and obtain parent's
properties easily .... for instance computing values in the
formatters ) ?

Thanks
Right now there is no way to do this unfortunately.  Please feel free
to file a bug report and I'll have to think about how to best support
it.
the searching up the stack.
I guess I wasn't thinking that these name conflicts would be very
common.  Can you just rename your fields?
Andy
Post by peg
Hi,
I wanted to get a parent property value that exists in the current
{
   id: "parentId",
   ...
   child: { id: "childId", ... }
}
and produce in a template
{.section child }
  child id: {id} parentId: {?}
{.end}
perhaps a specific sign 'a la ' xpath could be used to indicate parent
../id or ^id
don't know.
Or it could be done by formatter accessing the current context, but
need then a way to get parent's context ...
treated ...
that's where I put  it for my needs for now
Phil
--
You received this message because you are subscribed to the Google Groups "JSON Template" group.
For more options, visit this group athttp://groups.google.com/group/json-template?hl=en.
--
You received this message because you are subscribed to the Google Groups "JSON Template" group.
To post to this group, send email to json-template-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to json-template+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/json-template?hl=en.
Andy Chu
2010-02-23 05:10:37 UTC
Permalink
Post by peg
Of course if you are producer of json datas you can change all
properties name ... even if that's not so easy when json is produced
from beans that you can't change easily.
Anyway, the more general question is : do we need xpath like
expression to navigate in json data structure (and obtain parent's
properties easily .... for instance computing values in the
formatters ) ?
It's crossed my mind. Personally I never ran into the need hard
enough. There is essentially a trivial subset of JSONPath already:

http://goessner.net/articles/JsonPath/

Namely the dot operator, foo.bar.baz.

I think if we just added $ from JSONPath that would address your use
case, right? You can build up from the root. And probably issue 53
as well: http://code.google.com/p/json-template/issues/detail?id=52&colspec=ID%20Type%20Status%20Priority%20Milestone%20Owner%20Todo%20Summary

Andy
--
You received this message because you are subscribed to the Google Groups "JSON Template" group.
To post to this group, send email to json-template-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
To unsubscribe from this group, send email to json-template+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit this group at http://groups.google.com/group/json-template?hl=en.
Loading...