Thread: [json-lib-user] Incompatibilities in encoding JSON objects
Brought to you by:
aalmiray
From: Thomas W. <tho...@du...> - 2009-01-10 19:50:47
|
Hi Chaps,I have noticed a difference in the encoding of JSON objects when the key I am encoding looks like a Javascript function. If I try the following: final JSONObject obj = new JSONObject(); obj.accumulate("key","value"); System.out.println(obj.toString()); It outputs: {"key" : "value"} If however I try this instead: final JSONObject obj = new JSONObject(); obj.accumulate("key","function(value){}"); System.out.println(obj.toString()); It outputs: {"key" : function(value){}} Note the lack of quote marks around the value. Is there any way I can force it to add quote marks around that value? regards, Tom -- Thomas Williams Java Programmer Dubit Limited +44 1133 947920 www.dubitlimited.com |
From: Thomas W. <tho...@du...> - 2009-01-10 22:23:14
|
Hi Chaps,I have noticed a difference in the encoding of JSON objects when the key I am encoding looks like a Javascript function. If I try the following: final JSONObject obj = new JSONObject(); obj.accumulate("key","value"); System.out.println(obj.toString()); It outputs: {"key" : "value"} If however I try this instead: final JSONObject obj = new JSONObject(); obj.accumulate("key","function(value){}"); System.out.println(obj.toString()); It outputs: {"key" : function(value){}} Note the lack of quote marks around the value. Is there any way I can force it to add quote marks around that value? regards, Tom -- Thomas Williams Java Programmer Dubit Limited +44 1133 947920 www.dubitlimited.com |
From: Thomas W. <tho...@du...> - 2009-01-11 12:44:31
|
Thanks Morgan,I did try this, and it does force json-lib to put quotes around the value, however it then also adds the quotes that I've put in manually! So you end up with: { "key" : "\"function(value){}\"" } Tom 2009/1/10 Morgan Packard <mpa...@ke...> > just a guess, I should say. But that's what I'd try first. > > > On Sat, Jan 10, 2009 at 6:11 PM, Morgan Packard <mpa...@ke...>wrote: > >> escape the quotes. >> >> I think: >> >> obj.accumulate("key","\"function(value){}\""); >> >> On Sat, Jan 10, 2009 at 4:33 PM, Thomas Williams < >> tho...@du...> wrote: >> >>> Hi Chaps, I have noticed a difference in the encoding of JSON objects >>> when the key I am encoding looks like a Javascript function. If I try the >>> following: >>> >>> >>> final JSONObject obj = new JSONObject(); >>> obj.accumulate("key","value"); >>> System.out.println(obj.toString()); >>> >>> It outputs: >>> >>> {"key" : "value"} >>> >>> If however I try this instead: >>> >>> final JSONObject obj = new JSONObject(); >>> obj.accumulate("key","function(value){}"); >>> System.out.println(obj.toString()); >>> >>> It outputs: >>> >>> {"key" : function(value){}} >>> >>> Note the lack of quote marks around the value. Is there any way I can >>> force it to add quote marks around that value? >>> >>> regards, >>> Tom >>> >>> -- >>> Thomas Williams >>> Java Programmer >>> Dubit Limited >>> +44 1133 947920 >>> www.dubitlimited.com >>> >>> >>> ------------------------------------------------------------------------------ >>> Check out the new SourceForge.net Marketplace. >>> It is the best place to buy or sell services for >>> just about anything Open Source. >>> http://p.sf.net/sfu/Xq1LFB >>> _______________________________________________ >>> json-lib-user mailing list >>> jso...@li... >>> https://lists.sourceforge.net/lists/listinfo/json-lib-user >>> >>> >> >> >> -- >> +++++++++++++++++++++++++++++++++++++++ >> morganpackard.com >> myspace.com/morganpackard >> finediving.org >> anticipaterecordings.com >> (646) 206-8337 >> > > > > -- > +++++++++++++++++++++++++++++++++++++++ > morganpackard.com > myspace.com/morganpackard > finediving.org > anticipaterecordings.com > (646) 206-8337 > -- Thomas Williams Java Programmer Dubit Limited +44 1133 947920 www.dubitlimited.com |
From: Thomas W. <tho...@du...> - 2009-01-11 22:19:20
|
Morgan,I'm having a play around with couch DB which has a JSON interface, and for some reason the interface to some of the functions require you to send the functions enclosed in quote marks, I guess the erlang JSON libraries must be a little stricter in their definition of what is JSON (there isn't a 'function' keyword in strict JSON is there?) Anyway, I think I can find find a way around this another way, but thanks for your insights. Tom 2009/1/11 Morgan Packard <hel...@gm...> > Well, my stab in the dark didn't work. Just curious--why do you need a > string that looks like a function anyway? > > Sent from my iPhone > > On Jan 11, 2009, at 6:30 AM, Thomas Williams < > tho...@du...> wrote: > > Thanks Morgan,I did try this, and it does force json-lib to put quotes > around the value, however it then also adds the quotes that I've put in > manually! So you end up with: > > { "key" : "\"function(value){}\"" } > > Tom > > 2009/1/10 Morgan Packard < <mpa...@ke...> > mpa...@ke...> > >> just a guess, I should say. But that's what I'd try first. >> >> >> On Sat, Jan 10, 2009 at 6:11 PM, Morgan Packard <<mpa...@ke...> >> mpa...@ke...> wrote: >> >>> escape the quotes. >>> >>> I think: >>> >>> obj.accumulate("key","\"function(value){}\""); >>> >>> On Sat, Jan 10, 2009 at 4:33 PM, Thomas Williams <<tho...@du...> >>> tho...@du...> wrote: >>> >>>> Hi Chaps, I have noticed a difference in the encoding of JSON objects >>>> when the key I am encoding looks like a Javascript function. If I try the >>>> following: >>>> >>>> >>>> final JSONObject obj = new JSONObject(); >>>> obj.accumulate("key","value"); >>>> System.out.println(obj.toString()); >>>> >>>> It outputs: >>>> >>>> {"key" : "value"} >>>> >>>> If however I try this instead: >>>> >>>> final JSONObject obj = new JSONObject(); >>>> obj.accumulate("key","function(value){}"); >>>> System.out.println(obj.toString()); >>>> >>>> It outputs: >>>> >>>> {"key" : function(value){}} >>>> >>>> Note the lack of quote marks around the value. Is there any way I can >>>> force it to add quote marks around that value? >>>> >>>> regards, >>>> Tom >>>> >>>> -- >>>> Thomas Williams >>>> Java Programmer >>>> Dubit Limited >>>> +44 1133 947920 >>>> <http://www.dubitlimited.com>www.dubitlimited.com >>>> >>>> >>>> ------------------------------------------------------------------------------ >>>> Check out the new SourceForge.net Marketplace. >>>> It is the best place to buy or sell services for >>>> just about anything Open Source. >>>> <http://p.sf.net/sfu/Xq1LFB>http://p.sf.net/sfu/Xq1LFB >>>> _______________________________________________ >>>> json-lib-user mailing list >>>> <jso...@li...> >>>> jso...@li... >>>> <https://lists.sourceforge.net/lists/listinfo/json-lib-user> >>>> https://lists.sourceforge.net/lists/listinfo/json-lib-user >>>> >>>> >>> >>> >>> -- >>> +++++++++++++++++++++++++++++++++++++++ >>> morganpackard.com >>> <http://myspace.com/morganpackard>myspace.com/morganpackard >>> finediving.org >>> anticipaterecordings.com >>> (646) 206-8337 >>> >> >> >> >> -- >> +++++++++++++++++++++++++++++++++++++++ >> morganpackard.com >> <http://myspace.com/morganpackard>myspace.com/morganpackard >> finediving.org >> anticipaterecordings.com >> (646) 206-8337 >> > > > > -- > Thomas Williams > Java Programmer > Dubit Limited > +44 1133 947920 > <http://www.dubitlimited.com>www.dubitlimited.com > > -- Thomas Williams Java Programmer Dubit Limited +44 1133 947920 www.dubitlimited.com |
From: Thomas W. <tho...@du...> - 2009-01-14 09:05:49
|
Hi Andres,I am using version 2.2.3. Regards, Tom 2009/1/14 Andres Almiray <aal...@ya...> > Hi Thomas, > > Sorry for the late reply. I think we recently fixed a bug request regarding > couchdb and json-lib integration, which I believe should be in the latest > stable release, which version of json-lib are you testing with? > > Cheers, > Andres > > ------------------------------------------- > http://jroller.com/aalmiray > http://www.linkedin.com/in/aalmiray > -- > What goes up, must come down. Ask any system administrator. > There are 10 types of people in the world: Those who understand binary, and > those who don't. > To understand recursion, we must first understand recursion. > > ------------------------------ > *From:* Thomas Williams <tho...@du...> > *To:* Morgan Packard <hel...@gm...>; > jso...@li... > *Sent:* Sunday, January 11, 2009 2:19:13 PM > *Subject:* Re: [json-lib-user] Incompatibilities in encoding JSON objects > > Morgan,I'm having a play around with couch DB which has a JSON interface, > and for some reason the interface to some of the functions require you to > send the functions enclosed in quote marks, I guess the erlang JSON > libraries must be a little stricter in their definition of what is JSON > (there isn't a 'function' keyword in strict JSON is there?) Anyway, I think > I can find find a way around this another way, but thanks for your insights. > > Tom > > 2009/1/11 Morgan Packard <hel...@gm...> > >> Well, my stab in the dark didn't work. Just curious--why do you need a >> string that looks like a function anyway? >> >> Sent from my iPhone >> >> On Jan 11, 2009, at 6:30 AM, Thomas Williams < >> tho...@du...> wrote: >> >> Thanks Morgan, I did try this, and it does force json-lib to put quotes >> around the value, however it then also adds the quotes that I've put in >> manually! So you end up with: >> >> { "key" : "\"function(value){}\"" } >> >> Tom >> >> 2009/1/10 Morgan Packard < <mpa...@ke...> >> mpa...@ke...> >> >>> just a guess, I should say. But that's what I'd try first. >>> >>> >>> On Sat, Jan 10, 2009 at 6:11 PM, Morgan Packard <<mpa...@ke...> >>> mpa...@ke...> wrote: >>> >>>> escape the quotes. >>>> >>>> I think: >>>> >>>> obj.accumulate("key","\"function(value){}\""); >>>> >>>> On Sat, Jan 10, 2009 at 4:33 PM, Thomas Williams <<tho...@du...> >>>> tho...@du...> wrote: >>>> >>>>> Hi Chaps, I have noticed a difference in the encoding of JSON objects >>>>> when the key I am encoding looks like a Javascript function. If I try the >>>>> following: >>>>> >>>>> >>>>> final JSONObject obj = new JSONObject(); >>>>> obj.accumulate("key","value"); >>>>> System.out.println(obj.toString()); >>>>> >>>>> It outputs: >>>>> >>>>> {"key" : "value"} >>>>> >>>>> If however I try this instead: >>>>> >>>>> final JSONObject obj = new JSONObject(); >>>>> obj.accumulate("key","function(value){}"); >>>>> System.out.println(obj.toString()); >>>>> >>>>> It outputs: >>>>> >>>>> {"key" : function(value){}} >>>>> >>>>> Note the lack of quote marks around the value. Is there any way I can >>>>> force it to add quote marks around that value? >>>>> >>>>> regards, >>>>> Tom >>>>> >>>>> -- >>>>> Thomas Williams >>>>> Java Programmer >>>>> Dubit Limited >>>>> +44 1133 947920 >>>>> <http://www.dubitlimited.com>www.dubitlimited.com >>>>> >>>>> >>>>> ------------------------------------------------------------------------------ >>>>> Check out the new SourceForge.net Marketplace. >>>>> It is the best place to buy or sell services for >>>>> just about anything Open Source. >>>>> <http://p.sf.net/sfu/Xq1LFB>http://p.sf.net/sfu/Xq1LFB >>>>> _______________________________________________ >>>>> json-lib-user mailing list >>>>> <jso...@li...> >>>>> jso...@li... >>>>> <https://lists.sourceforge.net/lists/listinfo/json-lib-user> >>>>> https://lists.sourceforge.net/lists/listinfo/json-lib-user >>>>> >>>>> >>>> >>>> >>>> -- >>>> +++++++++++++++++++++++++++++++++++++++ >>>> morganpackard.com >>>> <http://myspace.com/morganpackard>myspace.com/morganpackard >>>> finediving.org >>>> anticipaterecordings.com >>>> (646) 206-8337 >>>> >>> >>> >>> >>> -- >>> +++++++++++++++++++++++++++++++++++++++ >>> morganpackard.com >>> <http://myspace.com/morganpackard>myspace.com/morganpackard >>> finediving.org >>> anticipaterecordings.com >>> (646) 206-8337 >>> >> >> >> >> -- >> Thomas Williams >> Java Programmer >> Dubit Limited >> +44 1133 947920 >> <http://www.dubitlimited.com>www.dubitlimited.com >> >> > > > -- > Thomas Williams > Java Programmer > Dubit Limited > +44 1133 947920 > www.dubitlimited.com > > -- Thomas Williams Java Programmer Dubit Limited +44 1133 947920 www.dubitlimited.com |