Loading ...
Sorry, an error occurred while loading the content.

Re: json keys

Expand Messages
  • marcrbraincast
    ... UNIQUEIDS :[ js63013 , js63009 ], ...
    Message 1 of 15 , Jun 27, 2007
    • 0 Attachment
      --- In json@yahoogroups.com, "Mark Ireland" <markincuba@...> wrote:
      >
      >
      > For a smaller jsObject can there be a json variable like this:
      >
      > {"totalItems":40, "itemsFound":2,
      "UNIQUEIDS":["js63013","js63009"],
      > "columnnames":["Company,Title,Name,Phone,Email"], items: ["js63013":
      > {"A1 Services",
      > "CEO",
      > "Jane Jones",
      > "800-555-2121",
      > "janejones@..."},
      >
      > "js63009":{"Acme",
      > "President",
      > "John Smith",
      > "800-555-1212",
      > "johnsmith@..."}
      > ]}
      >
      >
      > rather than this:
      >
      > {SalesDatabase2:
      > {totalItems:40, itemsFound:2, items: [
      > {Company:"A1 Services",
      > Title:"CEO",
      > Name:"Jane Jones",
      > Phone:"800-555-2121",
      > Email:"janejones@..."},
      >
      > {Company:"Acme",
      > Title:"President",
      > Name:"John Smith",
      > Phone:"800-555-1212",
      > Email:"johnsmith@..."}
      > ]}
      > }
      >
      > _________________________________________________________________
      > Advertisement: ninemsn Travel - Hot deals, travel ideas & Lonely Planet
      > guides.
      >
      http://ninemsn.com.au/share/redir/adTrack.asp?mode=click&clientID=799&referral=hotmailtagline&URL=http://travel.ninemsn.com.au/compIntro.aspx?compId=2404
      >

      Then it would probably become something like this:

      {"totalItems":40,"itemsFound":2,"UNIQUEIDS":["js63013","js63009"],"columnnames":["Company","Title","Name","Phone","Email"],"items":{"js63013":["A1
      Services","CEO","Jane Jones","800-555-2121","janejones@a1service
      s.com"],"js63009":[" Acme","President","John
      Smith","800-555-1212","johnsmith@acme. com"]}}

      But although that probably results in a somewhat smaller json string I
      don't really see a benefit, in fact, the object looks a lot more
      difficult to get the value's form.
    • marcrbraincast
      ... Planet ...
      Message 2 of 15 , Jun 27, 2007
      • 0 Attachment
        --- In json@yahoogroups.com, "marcrbraincast" <marcrbraincast@...> wrote:
        >
        > --- In json@yahoogroups.com, "Mark Ireland" <markincuba@> wrote:
        > >
        > >
        > > For a smaller jsObject can there be a json variable like this:
        > >
        > > {"totalItems":40, "itemsFound":2,
        > "UNIQUEIDS":["js63013","js63009"],
        > > "columnnames":["Company,Title,Name,Phone,Email"], items: ["js63013":
        > > {"A1 Services",
        > > "CEO",
        > > "Jane Jones",
        > > "800-555-2121",
        > > "janejones@"},
        > >
        > > "js63009":{"Acme",
        > > "President",
        > > "John Smith",
        > > "800-555-1212",
        > > "johnsmith@"}
        > > ]}
        > >
        > >
        > > rather than this:
        > >
        > > {SalesDatabase2:
        > > {totalItems:40, itemsFound:2, items: [
        > > {Company:"A1 Services",
        > > Title:"CEO",
        > > Name:"Jane Jones",
        > > Phone:"800-555-2121",
        > > Email:"janejones@"},
        > >
        > > {Company:"Acme",
        > > Title:"President",
        > > Name:"John Smith",
        > > Phone:"800-555-1212",
        > > Email:"johnsmith@"}
        > > ]}
        > > }
        > >
        > > _________________________________________________________________
        > > Advertisement: ninemsn Travel - Hot deals, travel ideas & Lonely
        Planet
        > > guides.
        > >
        >
        http://ninemsn.com.au/share/redir/adTrack.asp?mode=click&clientID=799&referral=hotmailtagline&URL=http://travel.ninemsn.com.au/compIntro.aspx?compId=2404
        > >
        >
        > Then it would probably become something like this:
        >
        >
        {"totalItems":40,"itemsFound":2,"UNIQUEIDS":["js63013","js63009"],"columnnames":["Company","Title","Name","Phone","Email"],"items":{"js63013":["A1
        > Services","CEO","Jane Jones","800-555-2121","janejones@a1service
        > s.com"],"js63009":[" Acme","President","John
        > Smith","800-555-1212","johnsmith@acme. com"]}}
        >
        > But although that probably results in a somewhat smaller json string I
        > don't really see a benefit, in fact, the object looks a lot more
        > difficult to get the value's form.
        >

        grrr.... let's try that again... :/


        {"totalItems":40,
        "itemsFound":2,
        "UNIQUEIDS":["js63013","js63009"],
        "columnnames":["Company","Title","Name","Phone","Email"],
        "items":{"js63013":
        ["A1 Services","CEO","Jane Jones",
        "800-555-2121","janejones@..."],
        "js63009":
        [" Acme","President","John Smith",
        "800-555-1212","johnsmith@acme. com"]}}
      • Don Owens
        Do you mean the other way around? I.e., using unquoted keys? The JSON spec says that the keys must be quoted. The reason for this is that there is a bug in
        Message 3 of 15 , Jun 28, 2007
        • 0 Attachment
          Do you mean the other way around? I.e., using unquoted keys? The
          JSON spec says that the keys must be quoted. The reason for this is
          that there is a bug in Javascript where it will treat a key as a
          keyword if it is unquoted and matches a keyword. Javascript is not
          smart enough to realize it should not be treating the key as a keyword.


          --- In json@yahoogroups.com, "Mark Ireland" <markincuba@...> wrote:
          >
          >
          > For a smaller jsObject can there be a json variable like this:
          >
          > {"totalItems":40, "itemsFound":2,
          "UNIQUEIDS":["js63013","js63009"],
          > "columnnames":["Company,Title,Name,Phone,Email"], items: ["js63013":
          > {"A1 Services",
          > "CEO",
          > "Jane Jones",
          > "800-555-2121",
          > "janejones@..."},
          >
          > "js63009":{"Acme",
          > "President",
          > "John Smith",
          > "800-555-1212",
          > "johnsmith@..."}
          > ]}
          >
          >
          > rather than this:
          >
          > {SalesDatabase2:
          > {totalItems:40, itemsFound:2, items: [
          > {Company:"A1 Services",
          > Title:"CEO",
          > Name:"Jane Jones",
          > Phone:"800-555-2121",
          > Email:"janejones@..."},
          >
          > {Company:"Acme",
          > Title:"President",
          > Name:"John Smith",
          > Phone:"800-555-1212",
          > Email:"johnsmith@..."}
          > ]}
          > }
          >
          > _________________________________________________________________
          > Advertisement: ninemsn Travel - Hot deals, travel ideas & Lonely Planet
          > guides.
          >
          http://ninemsn.com.au/share/redir/adTrack.asp?mode=click&clientID=799&referral=hotmailtagline&URL=http://travel.ninemsn.com.au/compIntro.aspx?compId=2404
          >
        • Don Owens
          Yes, via the parseJSON method called on a string (see http://www.json.org/json.js). Don t use eval() unless the JSON is from a trusted source, i.e., you know
          Message 4 of 15 , Jun 28, 2007
          • 0 Attachment
            Yes, via the parseJSON method called on a string (see
            http://www.json.org/json.js). Don't use eval() unless the JSON is
            from a trusted source, i.e., you know there are no function calls in
            there.


            --- In json@yahoogroups.com, "timgerr" <tim.gallagher@...> wrote:
            >
            > --- In json@yahoogroups.com, "marcrbraincast" <marcrbraincast@>
            > wrote:
            > >
            > > --- In json@yahoogroups.com, "timgerr" <tim.gallagher@> wrote:
            > > >
            > > <cut>
            > > > >
            > > > > The page reads:
            > > > >
            > > > > Dependencies
            > > > > JSONError.js
            > > > >
            > > > > I guess you need that file included too...
            > > > >
            > > >
            > > >
            > > > Thank you for the information, I guess that I need to read
            > better.
            > > > Here is the biggest question that I have, lets say I have a
            > string
            > > >
            > > > var test = {"outPut":[{"name":"Michelle Gallagher"},{"name":"Bob
            > > > Jones"},{"name":"tester"},{"name":"Administrator"}]};
            > > >
            > > > Can I decode this back into an object?
            > > >
            > > > Thanks again for the help,
            > > > -T
            > > >
            > >
            > > the var test is already an object.
            > > It's an object with one array which holds 4 objects.
            > >
            > > var str = "{'output':['name':'Michelle']}";
            > > would make a string...
            > >
            >
            >
            > I am new to some of this so I might not be clear, I am woking with
            > ajax and I am getting a string returned from another webpage that is
            > JSON encoded. When I recieve it it is then consittered a string. I
            > would like to take this returned string
            > {"outPut":[{"name":"Michelle Gallagher"},{"name":"Bob Jones"},
            > {"name":"tester"},{"name":"Administrator"}]}
            > and put it back into a javascript object. Can I do that with decode?
            >
            > Thanks for the help,
            > -T
            >
          • Mark Ireland
            Somewhat smaller? I was thinking a large object would be shrunk by half because there would be no repetition of the columnnames everywhere. . ... And I thought
            Message 5 of 15 , Jun 28, 2007
            • 0 Attachment
              Somewhat smaller? I was thinking a large object would be shrunk by half
              because there would be no repetition of the columnnames everywhere. . ...

              And I thought my idea would make getting a value as easy as

              myJSON["js63009"].Company

              I suppose the list of columnnames could be an array since people would
              propbably make it into one so they can loop over it?

              >Then it would probably become something like this:
              >
              >{"totalItems":40,"itemsFound":2,"UNIQUEIDS":["js63013","js63009"],"columnnames":["Company","Title","Name","Phone","Email"],"items":{"js63013":["A1
              >Services","CEO","Jane Jones","800-555-2121","janejones@a1service
              >s.com"],"js63009":[" Acme","President","John
              >Smith","800-555-1212","johnsmith@acme. com"]}}
              >
              >But although that probably results in a somewhat smaller json string I
              >don't really see a benefit, in fact, the object looks a lot more
              >difficult to get the value's form.
              >
              >

              _________________________________________________________________
              Advertisement: ninemsn Travel - Hot deals, travel ideas & Lonely Planet
              guides.
              http://ninemsn.com.au/share/redir/adTrack.asp?mode=click&clientID=799&referral=hotmailtagline&URL=http://travel.ninemsn.com.au/compIntro.aspx?compId=2404
            • marcrbraincast
              Okay, fair enough... it will get smaller... You could indeed loose the list of columns and even the UNIQUEIDS and the totalItems... Not sure what the
              Message 6 of 15 , Jun 29, 2007
              • 0 Attachment
                Okay, fair enough... it will get smaller...
                You could indeed loose the list of columns and even the UNIQUEIDS and
                the totalItems...

                Not sure what the itemsFound does...


                var j = {"itemsFound":2,
                "items":[
                {"js63013":["A1 Services","CEO","Jane
                Jones","800-555-2121","janejones@..."]},
                {"js63009":[" Acme","President","John
                Smith","800-555-1212","johnsmith@acme. com"]}
                ]
                };
                window.onload = function(){
                var txt = "";
                var col = j.items;
                var totalitems = j.items.length;
                for (var i=0;i<totalitems;i++){
                for (j in col[i]){
                txt += col[i][j] + " \n";
                }

                }
                alert(totalitems + "\n" + txt);
                }







                --- In json@yahoogroups.com, "Mark Ireland" <markincuba@...> wrote:
                >
                >
                > Somewhat smaller? I was thinking a large object would be shrunk by half
                > because there would be no repetition of the columnnames everywhere.
                . ...
                >
                > And I thought my idea would make getting a value as easy as
                >
                > myJSON["js63009"].Company
                >
                > I suppose the list of columnnames could be an array since people would
                > propbably make it into one so they can loop over it?
                >
                > >Then it would probably become something like this:
                > >
                >
                >{"totalItems":40,"itemsFound":2,"UNIQUEIDS":["js63013","js63009"],"columnnames":["Company","Title","Name","Phone","Email"],"items":{"js63013":["A1
                > >Services","CEO","Jane Jones","800-555-2121","janejones@a1service
                > >s.com"],"js63009":[" Acme","President","John
                > >Smith","800-555-1212","johnsmith@acme. com"]}}
                > >
                > >But although that probably results in a somewhat smaller json string I
                > >don't really see a benefit, in fact, the object looks a lot more
                > >difficult to get the value's form.
                > >
                > >
                >
              Your message has been successfully submitted and would be delivered to recipients shortly.