My Format. No iteration required.
{"ListLanguages":[{"LANGUAGEID":"111","LANGUAGE":"Aderi","LANGUAGECODE":"AD"},{"LANGUAGEID":"112","LANGUAGE":"Afghani","LANGUAGECODE":"AF"},{"LANGUAGEID":"113","LANGUAGE":"African
Creole/Krahn","LANGUAGECODE":"AC"},{"LANGUAGEID":"114","LANGUAGE":"Afrikaans","LANGUAGECODE":"AK"},{"LANGUAGEID":"115","LANGUAGE":"Akan","LANGUAGECODE":"AQ"},{"LANGUAGEID":"116","LANGUAGE":"Albanian","LANGUAGECODE":"AL"},{"LANGUAGEID":"117","LANGUAGE":"Amharic","LANGUAGECODE":"AM"},{"LANGUAGEID":"118","LANGUAGE":"Arabic","LANGUAGECODE":"AR"},{"LANGUAGEID":"119","LANGUAGE":"arabic
juba","LANGUAGECODE":"AJ"},{"LANGUAGEID":"120","LANGUAGE":"Armenian","LANGUAGECODE":"AN"},{"LANGUAGEID":"121","LANGUAGE":"Ashanh","LANGUAGECODE":"AS"},{"LANGUAGEID":"122","LANGUAGE":"Assyrian","LANGUAGECODE":"AY"},{"LANGUAGEID":"123","LANGUAGE":"Azeri
(Turkish)","LANGUAGECODE":"AZ"},{"LANGUAGEID":"124","LANGUAGE":"Badini","LANGUAGECODE":"BD"},{"LANGUAGEID":"125","LANGUAGE":"Bajuni","LANGUAGECODE":"BJ"},{"LANGUAGEID":"126","LANGUAGE":"Balochi","LANGUAGECODE":"BA"},{"LANGUAGEID":"127","LANGUAGE":"Bambara","LANGUAGECODE":"BB"},{"LANGUAGEID":"128","LANGUAGE":"Bangladeshi","LANGUAGECODE":"BI"},{"LANGUAGEID":"129","LANGUAGE":"Bantu","LANGUAGECODE":"BT"},{"LANGUAGEID":"130","LANGUAGE":"Basque","LANGUAGECODE":"BQ"}]}
Another good example.
On Thu, Sep 8, 2011 at 11:30 PM, Justin Edwards
You can see an example on the coldfusionjedi link I posted originally.
Nothing I tried was as simple as the solution I posted.
toJSON returns the data properly formatted. If you didn't use plain
it would further complicate your data.
Also JSONP doesn't have strict origin policy (sometimes a headache).
http://api.jquery.com/jQuery.ajax/
Yes I did experiment with that when coming up with a simple solution
for array of structs type formatted JSON.
{"ROWCOUNT":2, "COLUMNS":["CITY","STATE"],"DATA":{"City":["Newton","San
Jose"],"State":["MA","CA"]}}
vs
{"COLUMNS":["CITY","STATE"],"DATA":[["Newton","MA"],["San Jose","CA"]]}
but each row {"COLUMN1":"Value", "COLUMN2":"Value"} is much more
portable, but not a native option
Also there is work going into a more secure JSONP standard. http://json-p.org/
You can see here that people have worked around this formatting in
coldfusion since 2007
http://www.sencha.com/forum/showthread.php?20790-Using-Coldfusion-to-provide-json-data
Getting a bit OT, isn't JSONP somewhat unecessary now XHR policy is supported by a majority of browsers? I guess it doesn't help much if a consumer dictates you must provide JSONP.
Either way, it'd be nice to have some built in functionality to flatten queries to arrays. Or have them converted by setting an attribute on cffunction.
http://services.digg.com/stories/top?appkey=http%3A%2F%2Fmashup.com&type=javascript
&callback=?
http://local.yahooapis.com/LocalSearchService/V3/localSearch?appid=YahooDemo&query=pizza&zip=10504&results=2&output=json&callback=?
http://www.geonames.org/postalCodeLookupJSON?postalcode=10504&country=US&callback=?
http://cache.addthiscdn.com/services/v1/sharing.en.jsonp#jsonpcallback=callback_fn_name
http://twitter.com/status/user_timeline/USERNAME.json?count=10
&callback=?
He will read all of this in the morning and will probably come up with
better solutions from your advice. I've stayed up pretty late
tonight testing things out. (3:15am my time)
The speed is going to be in the data transfer. Especially large data sets.
I used to bitch about how queries were formatted (That's not JSON!
(yes, it is)) when serialized to JSON, but I had the revelation of what
Micha just mentioned-- what a waste! Why push the *exact same* data
across the line so many times?
FWIW, if you use ORM, serializeJSON will work the way you'd expect on
object queries (cuz they're objects vs. rows of data), but you do have
to be careful about relationships (the serialization process will grab
things marked as "lazy", producing more queries & JSON objects than you
might at first expect). That's hard-core JSON, including object trees.
It can be good or bad, depending on what and how you're doing stuff.
One of the reasons (sorry kitty!) that I love dojo is that they
abstracted away the data access. *Nothing* cares about how the data is
formatted, as it's going through a level of abstraction, and it's the
abstraction's responsibility to handle the actual data. To leverage
*cfquery* serialized JSON constructs I just added a simple loop in one
of the existing "data stores" and called it CFQueryDataStore (or
something like that). In sum, dojo widgets will happily consume JSON
format X, CSV, XML, yadda yadda- without needing to change the widget
itself (and they've got some *awesome* widgets) ;]p).
It's trivial to do it on the client side, and so long as you're not
using eval in yer loop, I'd reckon it would be a far sight faster to let
the client assemble the JSON into the format it needs, vs. pushing say,
600k across the wire when there's only 100k of actual data.
All that said, I *love* Micha's suggestion for serializeJSON! It's the
intuitive way to go about it, IMHO.
:Denny
--
Railo Technologies: getrailo.com Professional Open Source
skype: valliantster (505)510.1336 de...@getrailo.com
GnuPG-FP: DDEB 16E1 EF43 DCFD 0AEE 5CD0 964B B7B0 1C22 CB62
One of the reasons (sorry kitty!) that I love dojo is that theyabstracted away the data access.
Lost the reference?Some Americanism I should be aware of?Mark Drew
Railo Technologies, Ltd.
Professional Open Source
skype: mark_railo
ma...@getrailo.com
+44 7971 852296
www.getrailo.com
Good news! I proposed, and it accepted!
The wedding will be in Utah (I'm already married) around July. I'm
having a body fabricated for "her" in Japan.
Wife #1 said that only a robot could match my libido, so...
If I hear any jokes about her "promiscuous" license, I'm knocking heads.
Oh, no doubt. I've put money in that g-string many a time. The awesome
part? Dojoette is right there with me. She's down for the group
action. ;)
http://www.sitepen.com/blog/2010/11/15/from-jquery-to-large-applications/
jQuery is "easy", I reckon, but...
http://www.slideshare.net/rmurphey/the-jquery-divide-5287573
Not that *anything* -- even a luscious fabricated silicone mistress --
can keep me from writing crappy code. :)
I talk a good game, but truthfully, I love 'em all. I don't care what
I've got to work with. There's goodness to structure and badness to
structure. It's all a delicate balancing act. Or, more of a dance, if
you will.
Speaking of... do I hear a beat dropping? I believe so!