JSON from robot (python) to gadget the right way

4 views
Skip to first unread message

Agustin Horischnik

unread,
Oct 21, 2009, 11:56:13 AM10/21/09
to Google Wave API
Hi, I have a python robot which updates the state of a gadget. What
would be the right way to pass a list/array to the gadget? I assume
it's encoding it in JSON, right? But what's the right way to do that?
I tried importing simplejson from Django but it didn't really work
very well.

Is anybody doing this kind of thing?

Thanks.
Agustin.

pamela (Google Employee)

unread,
Oct 21, 2009, 12:02:04 PM10/21/09
to google-...@googlegroups.com
Hi Agustin-

The "Row of 4" robot does that. Have you looked at it's code?

- pamela
Message has been deleted

Agustin Horischnik

unread,
Oct 21, 2009, 2:35:57 PM10/21/09
to Google Wave API
Hi Pamela, thanks for your answer.

I did look at Row of 4 code and I just double checked it but I think
it doesn't send anything more than strings or numbers as values within
the delta dictionary.

What I meant was something like this:


controls = document.Gadget('http://MYAPP.appspot.com/public/
controls.xml')
doc.AppendElement(controls)
delta = {}
foo = ['One', 'Two', 'Three']
delta['bar'] = foo
controls.SubmitDelta(delta)

I've tried this and an odd thing happens: the gadget doesn't get
appended to the blip but I see no errors in the log... The debug log
shows:

CONSTRUCTING gadget with:{'url': 'http://MYAPP.appspot.com/public/
controls.xml', 'foobar': ['One', 'Two', 'Three']}

Outgoing:
[...]
" property":{
"type":"GADGET",
"properties":{
"javaClass":"java.util.HashMap",
"map":{
"url":"http://MYAPP.appspot.com/public/
controls.xml",
"foobar":{
"javaClass":"java.util.HashMap",
"map":{
"javaClass":"java.util.ArrayList",
"list":{
"javaClass":"java.util.ArrayList",
"list":[
"One",
"Two",
"Three"
]

[...]


Is using a list object as a value in a dictionary not supported when
sending delta?

Cheers.
Agustin.



On Oct 21, 6:02 pm, "pamela (Google Employee)" <pamela...@gmail.com>
wrote:
> Hi Agustin-
> The "Row of 4" robot does that. Have you looked at it's code?http://wave-samples-gallery.appspot.com/about_app?app_id=36022

pamela (Google Employee)

unread,
Oct 21, 2009, 8:08:04 PM10/21/09
to google-...@googlegroups.com
Ah, got it. What was your experiencing with using simplejson? You should be able to serialize that object and pass it through the delta. We don't have a demo of that, but think it should work.

You could also consider using more complex keys, like viewerName-propertyName-subPropertyName, etc. That is a bit better in terms of concurrency.

- pamela

Agustin Horischnik

unread,
Oct 21, 2009, 8:56:46 PM10/21/09
to Google Wave API
> Ah, got it. What was your experiencing with using simplejson? You should be
> able to serialize that object and pass it through the delta. We don't have a
> demo of that, but think it should work.

I don't remember but I'll re-try simplejson and report back.

> You could also consider using more complex keys, like
> viewerName-propertyName-subPropertyName, etc. That is a bit better in terms
> of concurrency.

hmm... I'm not sure I get that... could you please give me an example
whenever you have the time?

Agustin.

pamela (Google Employee)

unread,
Oct 21, 2009, 9:05:49 PM10/21/09
to google-...@googlegroups.com
For example, if you are storing the information about a shape that a participant just drew:

You could do:
delta = {'pamela.fox': "{'color':'red','shape':'circle'}"}

Or, you could do:
delta = {'pamela.fox-color': 'red'}
delta = {'pamela.fox-shape': 'circle'}

It may seem less elegant, but it is better in terms of concurrency, as it means that I can independently change different properties.

Agustin Horischnik

unread,
Oct 21, 2009, 9:14:48 PM10/21/09
to google-...@googlegroups.com
Gotcha. Yeah, I can see why is better for concurrency.

Thanks for your help.

Agustin Horischnik

unread,
Oct 26, 2009, 7:17:38 AM10/26/09
to Google Wave API
Reporting back on serializing objects and submitting them as delta.

I tried again using simplejson and the result is what I described
earlier without explicitly encoding them: the gadget breaks (i.e. in
this case it doesn't get
appended to the blip) and yet I see no errors in the log.

Let me know if need more info.

Agustin.

Teddy Jasin

unread,
Oct 26, 2009, 11:06:09 AM10/26/09
to Google Wave API
Hi Agustin,

I think I'm also facing same issue with you.
in my case I'm sending data from the robot to the gadget also using
json, however my json data is arabic texts which is converted
unicode... so it become longer json strings.

the gadget will not show if the passed data is too long.
so I guess my json data is too big to be passed into the gadget.
anyone can help me in this?

Agustin Horischnik

unread,
Oct 26, 2009, 4:02:05 PM10/26/09
to google-...@googlegroups.com
Hi Teddy, can you paste a few lines from your outgoing json containing the strings you think could be causing the problem and maybe the bit of code you're using to submit the delta and encode it?

I ended up using Pamela's suggestion but I'll be happy to try your code and see if I find something.

Agustin.

Teddy Jasin

unread,
Oct 26, 2009, 11:59:16 PM10/26/09
to Google Wave API
Hi agustin,

here's the sample of some json I send to the gadget:

delta = {'surahcontent': u'\u0628\u0650\u0633\u0652\u0645\u0650
\u0627\u0644\u0644\u0651\u064e\u0647\u0650
\u0627\u0644\u0631\u0651\u064e\u062d\u0652\u0645\u064e
\u0670\u0646\u0650 \u0627\u0644\u0631\u0651\u064e\u062d\u0650\u064a
\u0645\u0650 \ufd3f \u0661\ufd3e\u0627\u0644\u0652\u062d\u064e
\u0645\u0652\u062f\u064f \u0644\u0650\u0644\u0651\u064e\u0647\u0650
\u0631\u064e\u0628\u0651\u0650 \u0627\u0644\u0652\u0639\u064e
\u0627\u0644\u064e\u0645\u0650\u064a\u0646\u064e \ufd3f \u0662\ufd3e',
'surahtitle': u'Al-Faatiha - The Opening (1-2)', 'translations':
u' (1) In the name of Allah, Most Gracious, Most Merciful.\n (2)
Praise be to Allah, the Cherisher and Sustainer of the worlds;\n'}

gadget.SubmitDelta(delta)


as u see the JSON I sending containing a long unicode strings, the
json above can successfuly show the gadget and show the content.
However when the delta above gets extremely long then it won't show
the gadget though no error in log file...

So I believe there's limit in the length of the delta that you can
send to gadget.

Teddy

On Oct 27, 4:02 am, Agustin Horischnik <agu...@gmail.com> wrote:
> Hi Teddy, can you paste a few lines from your outgoing json containing the
> strings you think could be causing the problem and maybe the bit of code
> you're using to submit the delta and encode it?
>
> I ended up using Pamela's suggestion but I'll be happy to try your code and
> see if I find something.
>
> Agustin.
>

Agustin Horischnik

unread,
Oct 27, 2009, 6:31:32 AM10/27/09
to Google Wave API
I'm not sure about the length. There's something about that in this
thread:
http://groups.google.com/group/google-wave-api/browse_thread/thread/803a29e47555f7f3/7a958b95aad29280?lnk=gst&q=100k#7a958b95aad29280

But I can tell you that I tried sending a string of 200000 '1's and it
didn't break the gadget. And it's not getting chopped (i.e. on the
gadget, it's javascript length property equals 200000).

You can try this yourself:

cont = ''
for i in range(200000):
cont += '1'

delta['cont'] = cont
gadget.SubmitDelta(delta)


What I did find playing with your code is this:

When I do:

delta = {}
delta['surahcontent'] = u'\u0628\u0644\u0651\u064e
\u0647\u0650\u0627\u0644\u0631\u0651\u064e\u062d\u0652\u0645\u064e'
gadget.SubmitDelta(delta)

I get no gadget and no error.


But if I encode the unicode string like so:
delta = {}
delta['surahcontent'] = u'\u0628\u0644\u0651\u064e
\u0647\u0650\u0627\u0644\u0631\u0651\u064e\u062d
\u0652\u0645\u064e'.encode('utf-8')
gadget.SubmitDelta(delta)

I get the gadget and the arabic caracters.

So I think what breaks the gadget is passing any thing other than a
string... If for instance I do:

delta['surahcontent'] = 1

it will fail. While doing:

delta['surahcontent'] = str(1)

will work.

Agustin.

Teddy Jasin

unread,
Oct 29, 2009, 12:50:24 AM10/29/09
to Google Wave API
hemm thanks agustin...
thats interesting, I havent tried that...

I do my work around of not passing big data to gadget by just
providing necessary data, the gadget then do an AJAX based on the data
passed by the robot and display it...
its seems faster this way... the gadget displayed faster and I don't
get HIGH CPU warning on my log...



On Oct 27, 6:31 pm, Agustin Horischnik <agu...@gmail.com> wrote:
> I'm not sure about the length. There's something about that in this
> thread:http://groups.google.com/group/google-wave-api/browse_thread/thread/8...

BI Guy

unread,
Oct 29, 2009, 7:55:19 AM10/29/09
to Google Wave API
I am trying to send some json data through JAVA Gadget.setField() and
sees the same issues with passing data. My experiments show that if
the string includes an embeded double quote(\") then it will pass the
value up to that character in string.

I believe, there is nothing wrong in embedding double quotes in a
string as they would be escaped anyway. Gadget.setField() is just
stopping as soon as it sees the double quote even if it is escaped.


This definitely should be fixed.

On Oct 29, 12:50 am, Teddy Jasin <jasin.te...@gmail.com> wrote:
> hemm thanks agustin...
> thats interesting, I havent tried that...
>
> I do my work around of not passing big data togadgetby just
> providing necessary data, thegadgetthen do an AJAX based on the data
> passed by the robot and display it...
> its seems faster this way... thegadgetdisplayed faster and I don't
> get HIGH CPU warning on my log...
>
> On Oct 27, 6:31 pm, Agustin Horischnik <agu...@gmail.com> wrote:
>
>
>
> > I'm not sure about the length. There's something about that in this
> > thread:http://groups.google.com/group/google-wave-api/browse_thread/thread/8...
>
> > But I can tell you that I tried sending a string of 200000 '1's and it
> > didn't break thegadget. And it's not getting chopped (i.e. on the
> >gadget, it's javascript length property equals 200000).
>
> > You can try this yourself:
>
> > cont = ''
> > for i in range(200000):
> >     cont += '1'
>
> > delta['cont'] = cont
> >gadget.SubmitDelta(delta)
>
> > What I did find playing with your code is this:
>
> > When I do:
>
> > delta = {}
> > delta['surahcontent'] = u'\u0628\u0644\u0651\u064e
> > \u0647\u0650\u0627\u0644\u0631\u0651\u064e\u062d\u0652\u0645\u064e'
> >gadget.SubmitDelta(delta)
>
> > I get nogadgetand no error.
>
> > But if I encode the unicode string like so:
> > delta = {}
> > delta['surahcontent'] = u'\u0628\u0644\u0651\u064e
> > \u0647\u0650\u0627\u0644\u0631\u0651\u064e\u062d
> > \u0652\u0645\u064e'.encode('utf-8')
> >gadget.SubmitDelta(delta)
>
> > I get thegadgetand the arabic caracters.
>
> > So I think what breaks thegadgetis passing any thing other than a
> > string... If for instance I do:
>
> > delta['surahcontent'] = 1
>
> > it will fail. While doing:
>
> > delta['surahcontent'] = str(1)
>
> > will work.
>
> > Agustin.
>
> > On Oct 27, 4:59 am, Teddy Jasin <jasin.te...@gmail.com> wrote:
>
> > > Hi agustin,
>
> > > here's the sample of some json I send to thegadget:
>
> > > delta = {'surahcontent': u'\u0628\u0650\u0633\u0652\u0645\u0650
> > > \u0627\u0644\u0644\u0651\u064e\u0647\u0650
> > > \u0627\u0644\u0631\u0651\u064e\u062d\u0652\u0645\u064e
> > > \u0670\u0646\u0650 \u0627\u0644\u0631\u0651\u064e\u062d\u0650\u064a
> > > \u0645\u0650 \ufd3f \u0661\ufd3e\u0627\u0644\u0652\u062d\u064e
> > > \u0645\u0652\u062f\u064f \u0644\u0650\u0644\u0651\u064e\u0647\u0650
> > > \u0631\u064e\u0628\u0651\u0650 \u0627\u0644\u0652\u0639\u064e
> > > \u0627\u0644\u064e\u0645\u0650\u064a\u0646\u064e \ufd3f \u0662\ufd3e',
> > > 'surahtitle': u'Al-Faatiha - The Opening (1-2)', 'translations':
> > > u' (1) In the name of Allah, Most Gracious, Most Merciful.\n (2)
> > > Praise be to Allah, the Cherisher and Sustainer of the worlds;\n'}
>
> > >gadget.SubmitDelta(delta)
>
> > > as u see the JSON I sending containing a long unicode strings, the
> > > json above can successfuly show thegadgetand show the content.
> > > However when the delta above gets extremely long then it won't show
> > > thegadgetthough no error in log file...
>
> > > So I believe there's limit in the length of the delta that you can
> > > send togadget.
>
> > > Teddy
>
> > > On Oct 27, 4:02 am, Agustin Horischnik <agu...@gmail.com> wrote:
>
> > > > Hi Teddy, can you paste a few lines from your outgoing json containing the
> > > > strings you think could be causing the problem and maybe the bit of code
> > > > you're using to submit the delta and encode it?
>
> > > > I ended up using Pamela's suggestion but I'll be happy to try your code and
> > > > see if I find something.
>
> > > > Agustin.
>
> > > > On Mon, Oct 26, 2009 at 4:06 PM, Teddy Jasin <jasin.te...@gmail.com> wrote:
>
> > > > > Hi Agustin,
>
> > > > > I think I'm also facing same issue with you.
> > > > > in my case I'm sending data from the robot to thegadgetalso using
> > > > > json, however my json data is arabic texts which is converted
> > > > > unicode... so it become longer json strings.
>
> > > > > thegadgetwill not show if the passed data is too long.
> > > > > so I guess my json data is too big to be passed into thegadget.
> > > > > anyone can help me in this?
>
> > > > > On Oct 26, 7:17 pm, Agustin Horischnik <agu...@gmail.com> wrote:
> > > > > > Reporting back on serializing objects and submitting them as delta.
>
> > > > > > I tried again using simplejson and the result is what I described
> > > > > > earlier without explicitly encoding them: thegadgetbreaks (i.e. in
> > > > > > this case it doesn't get
> > > > > > appended to the blip) and yet I see no errors in the log.
>
> > > > > > Let me know if need more info.
>
> > > > > > Agustin.
>
> > > > > > On Oct 22, 2:14 am, Agustin Horischnik <agu...@gmail.com> wrote:
>
> > > > > > > Gotcha. Yeah, I can see why is better for concurrency.
> > > > > > > Thanks for your help.
>
> > > > > > > On Thu, Oct 22, 2009 at 3:05 AM, pamela (Google Employee) <
>
> > > > > > > pamela...@gmail.com> wrote:
> > > > > > > > For example, if you are storing the information about a shape that a
> > > > > > > > participant just drew:
> > > > > > > > You could do:
> > > > > > > > delta = {'pamela.fox': "{'color':'red','shape':'circle'}"}
>
> > > > > > > > Or, you could do:
> > > > > > > > delta = {'pamela.fox-color': 'red'}
> > > > > > > > delta = {'pamela.fox-shape': 'circle'}
>
> > > > > > > > It may seem less elegant, but it is better in terms of concurrency,
> > > > > as it
> > > > > > > > means that I can independently change different properties.
>
> > > > > > > > On Thu, Oct 22, 2009 at 11:56 AM, Agustin Horischnik <
> > > > > agu...@gmail.com>wrote:
>
> > > > > > > >> > Ah, got it. What was your experiencing with using simplejson? You
> > > > > should
> > > > > > > >> be
> > > > > > > >> > able to serialize that object andpassit through the delta. We
Reply all
Reply to author
Forward
0 new messages