>
>
> Thanks. I was hoping there was a js function library where you just pass
> the
> unique id and the row is returned.
> Is there one?

What do you mean? There is no concept of "row" in JSON, or even unique IDs,
for that matter, beyond the property names in an object. Any structure you
are imposing on your JSON objects is your own, so there isn't going to be a
library out there to manipulate that unless you write it. ;-)

I could just loop through this testing for my uniqueID but surely someone
has written something quicker and more reusable than that? Is this not a
standard structure?

>From: "Martin Cooper" <mfncooper@...>
>Reply-To: json@yahoogroups.com
>To: json@yahoogroups.com
>Subject: Re: [json] json as js variable
>Date: Sun, 10 Dec 2006 14:13:22 -0800
>
>On 12/10/06, Mark Ireland <markincuba@...> wrote:
> >
> >
> > Thanks. I was hoping there was a js function library where you just pass
> > the
> > unique id and the row is returned.
> > Is there one?
>
>
>What do you mean? There is no concept of "row" in JSON, or even unique IDs,
>for that matter, beyond the property names in an object. Any structure you
>are imposing on your JSON objects is your own, so there isn't going to be a
>library out there to manipulate that unless you write it. ;-)
>
>--
>Martin Cooper
>

> Here is one I prepared earlier:
>
> {"RECORDCOUNT":30,"COLUMNLIST":"EM,EY,ISSILO,ISWEATHER,LATITUDE,LONGITUDE,PERCENTCOMPLETE,PERCENTQUALITY,SM,UNIQUEID,STATIONNAME,SY,X,Y","DATA":{"EM":[12,5,12,4,10,10,10,10,10,10,10,10,10,10,10,12,10,10,9,12,11,11,12,12,12,10,10,9,3,10],"EY":[2005,2005,2005,2006,2006,2006,2006,2006,2006,2006,2006,2006,2006,2006,2006,2006,2006,.
>
> . . . . . .
> .....,"X":[291,28,152,171,109,96,268,126,250,123,174,188,199,251,91,238,147,274,97,274,126,167,100,145,207,146,120,160,241,232],"Y":[136,188,197,226,212,211,128,113,126,179,197,175,176,148,51,147,252,153,66,180,224,158,83,73,122,131,151,250,178,134]}};
>
> I could just loop through this testing for my uniqueID but surely someone
> has written something quicker and more reusable than that? Is this not a
> standard structure?
>

Martin Cooper

... Depends on how you define standard , but no, it s not anything I would call a standard. I believe it s a format that comes from the CFJSON library, so

>
> Here is one I prepared earlier:
>
>
> {"RECORDCOUNT":30,"COLUMNLIST":"EM,EY,ISSILO,ISWEATHER,LATITUDE,LONGITUDE,PERCENTCOMPLETE,PERCENTQUALITY,SM,UNIQUEID,STATIONNAME,SY,X,Y","DATA":{"EM":[12,5,12,4,10,10,10,10,10,10,10,10,10,10,10,12,10,10,9,12,11,11,12,12,12,10,10,9,3,10],"EY":[2005,2005,2005,2006,2006,2006,2006,2006,2006,2006,2006,2006,2006,2006,2006,2006,2006,.
> . . . . . .
>
> .....,"X":[291,28,152,171,109,96,268,126,250,123,174,188,199,251,91,238,147,274,97,274,126,167,100,145,207,146,120,160,241,232],"Y":[136,188,197,226,212,211,128,113,126,179,197,175,176,148,51,147,252,153,66,180,224,158,83,73,122,131,151,250,178,134]}};
>
> I could just loop through this testing for my uniqueID but surely someone
> has written something quicker and more reusable than that? Is this not a
> standard structure?

Depends on how you define "standard", but no, it's not anything I would call
a standard. I believe it's a format that comes from the CFJSON library, so
that would be the place to look for helper code to access the data.

*Identifiers* are names for constants, variables, functions, loop labels, objects and classes. The first character must be an ASCII letter, underscore or

Message 9 of 19
, Dec 11, 2006

*Identifiers* are names for constants, variables, functions, loop labels,
objects and classes. The first character must be an ASCII letter, underscore
or dollar sign. Following characters can also include digits.

Even 'u80020' will do. You can only use numeric indexes if you are producing
an array.

--
Matthew P. C. Morley

[Non-text portions of this message have been removed]

Mark Ireland

Thanks, that got it working. Now I am wondering if there is some alternative to repeating the column names in every object. ...

Message 10 of 19
, Dec 17, 2006

Thanks, that got it working.

Now I am wondering if there is some alternative to repeating the column
names in every object.

You would have to do something more than a simple translation. If your end goal was to directly reference fields values by name, you would need to do an end

Message 13 of 19
, Dec 18, 2006

You would have to do something more than a simple translation.

If your end goal was to directly reference fields values by name, you would
need to do an end translation back to the object format in which you were
trying to avoid by duplicating names. Just a loop to recreate the data
object from the two arrays.

You have the knowledge of the fields names and could do your looping in
another manner, without direct reference anyway. Depends how exposed it is I
suppose and what level of work you want consumers of the data to do/know. I
found gzip an easier alternative than object rebuilding when looking at
performance in my projects

Depending on the size of your data and lots of other items, it is likely to
be faster for transmitting due to reduced payload, but it requires you to
deal with the arrays and not objects unless you rebuild them.

Hopefully I can clear all this up. First I wanted to save on whitespace by avoiding var myArray = new Array; cfloop var myArray[myIndex] = new Array;

Message 14 of 19
, Dec 18, 2006

Hopefully I can clear all this up. First I wanted to save on whitespace by
avoiding
var myArray = new Array;
cfloop
var myArray[myIndex] = new Array;
myArray[myIndex]['mycolumnName1']=#myQuery.myColumn1#;
myArray[myIndex]['mycolumnName2']=#myQuery.myColumn2#;
etc
/cfloop

Then I thought I could dynamically name form elements and get stuff from a
js object that I could reference with dot notation. (with myIndex as the id
of the element) Most of the stuff in the object is just flags that determine
how the page behaves.

If my goal is the shrink the page size what is the better approach?

Thanks

>From: "Matthew Morley" <WickedLogic@...>
>Reply-To: json@yahoogroups.com
>To: json@yahoogroups.com
>Subject: Re: [json] json as js variable
>Date: Mon, 18 Dec 2006 06:50:37 -0500
>
>You would have to do something more than a simple translation.
>
>If your end goal was to directly reference fields values by name, you would
>need to do an end translation back to the object format in which you were
>trying to avoid by duplicating names. Just a loop to recreate the data
>object from the two arrays.
>
>You have the knowledge of the fields names and could do your looping in
>another manner, without direct reference anyway. Depends how exposed it is
>I
>suppose and what level of work you want consumers of the data to do/know. I
>found gzip an easier alternative than object rebuilding when looking at
>performance in my projects
>
>Depending on the size of your data and lots of other items, it is likely to
>be faster for transmitting due to reduced payload, but it requires you to
>deal with the arrays and not objects unless you rebuild them.
>
>var row = MyStuff.u80020;
>var field_ISWEATHER = 3;
>var val = MyStuff.u80020[field_ISWEATHER];
>
>--
>Matthew P. C. Morley
>MPCM Technologies Inc.
>
>
>[Non-text portions of this message have been removed]
>

It would depend on what you mean by page and how much data you are dealing with. 3-10kb range might not make a huge difference on download, 20-300kb might. Run

Message 15 of 19
, Dec 19, 2006

It would depend on what you mean by page and how much data you are dealing
with. 3-10kb range might not make a huge difference on download, 20-300kb
might. Run some tests and time them in js, just keep in mind that they will
vary from machine to machine greatly. I keep a 433mhz celeron laptop around
to make sure I don't lose sight of performance too much.

If you are worried about transmission speed and you have a fairly big set of
data going, consider sizing it down. I know it sounds simple, but the
fastest way to speed up anything is to do less; less data, less parsing.
Don't optimize and worry about speed until you can prove it is running
slowly and that the program is only `thinking` as much as it needs to.

If that is not possible or desired, look at compressing the output with
something like gzip if the browser supports it, but the numbers all get down
to your data set. Using objects vs an object with an array of results and an
array of keys is just a matter for the code/coder. Depends who your consumer
is. If you want an object, send an object, and compress the communication
would be my stance.

Are you generating raw js right into the initial page? If yes, consider
moving it out into a separate request. That way you can do initial loads and
refresh with the data as it becomes available.

>objects and classes. The first character must be an ASCII letter,
>underscore
>or dollar sign. Following characters can also include digits.
>
>Even 'u80020' will do. You can only use numeric indexes if you are
>producing
>an array.
>
>--
>Matthew P. C. Morley
>
>
>[Non-text portions of this message have been removed]
>