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

Re: [ydn-javascript] datasource: json format expected

Expand Messages
  • Raphael Bauduin
    ... I got it working, though the JSON returned is different. Looking at datasource-beta-debug at line 1566, there s a test on resultsList, which is used if
    Message 1 of 12 , May 1, 2008
    • 0 Attachment
      >
      > There should be a way to use that json, or am I wrong?
      >

      I got it working, though the JSON returned is different.
      Looking at datasource-beta-debug at line 1566, there's a test on
      resultsList, which is used if present. The problem must be in
      walkPath:

      1566 if (schema.resultsList) {
      1567 path = buildPath(schema.resultsList);
      1568 if (path) {
      1569 resultsList = walkPath(path, oFullResponse);
      1570 if (resultsList === undefined) {
      1571 bError = true;
      1572 }
      1573 } else {
      1574 bError = true;
      1575 }
      1576 }


      The default behaviour is to consider the received data as an array,
      and it occurs when no resultsList is passed. So when returning all
      data in an array and using this code it works fine:

      myDataSource.responseSchema = {
      fields: ["url", "lock_version", "entity_url","details_url",
      "links_url", { "key": "status", "parser" : function(status) { "status"
      }}, {key:"title", parser: function(t){return "title"}} , {key:
      "deadline", parser: function(t){return "deadline"}},
      {key:"description", parser:function(v){return "description"}} ]
      };


      The downside is that there's no meta information available :(
      I don't have the opportunity to dig deeper right now, but will do
      later. So if you have any hints, don't hesitate to let me know ;-)

      Raph





      --
      Web database: http://www.myowndb.com
      Free Software Developers Meeting: http://www.fosdem.org
    • y_lsmith
      Raph, DataSource is capable of extracting values from nested structures . However, it looks like
      Message 2 of 12 , May 1, 2008
      • 0 Attachment
        Raph,

        DataSource is capable of extracting values from nested structures.  However, it looks like you want to capture the collection of values for your columns 'status', 'title', 'deadline', and 'description'.  Keep in mind that DataTable doesn't support tree like row structures, but you could use a custom formatter to turn the array data into a single cell value.  I threw together this example page  to show how to do it.

        Hope this helps,
        Luke

        --- In ydn-javascript@yahoogroups.com, "Raphael Bauduin" <rblists@...> wrote:
        >
        > Hi,
        >
        > Is the data source component able to work with this json?
        >
        > { "length" : 3,
        > "resources": [
        > { "url": "http://localhost:3000/instances/5.json",
        > "lock_version": 0,
        > "entity_url": "http://localhost:3000/entities/1.json",
        > "details_url": "http://localhost:3000/entities/1/details.json",
        > "links_url": "http://localhost:3000/instances/5/links.json",
        > "status": [
        > { "url": "http://localhost:3000/details/5/values/3.json",
        > "lock_version": 0,
        > "value": "On-hold"}
        > ],
        > "title": [
        > { "url": "http://localhost:3000/details/1/values/6.json",
        > "lock_version": 0, "value": "second test"}
        > ],
        > "deadline": [
        > { "url": "http://localhost:3000/details/4/values/3.json",
        > "lock_version": 0,
        > "value": "2008-05-01 15:35:50"}
        > ],
        > "description": [
        > { "url": "http://localhost:3000/details/2/values/7.json",
        > "lock_version": 0,
        > "value": "another descrpition"}
        > ]
        > }
        > ]
        > }
        >
        > As you can see there are nested objects. I always get a failure, even
        > when I try with parser functions.
        > Here is the latest version of my code, thanks for any hint to solve the problem.
        >
        > Raph
        >
        >
        > var oCallback = {
        > success: function(oRequest,oResponse,oPayload) {
        > console.log('success');
        > },
        > failure: function(oRequest,oResponse,oPayload) {
        > console.log('failure');
        > },
        > scope:this
        > }
        >
        > var myDataSource = new
        > YAHOO.util.DataSource("http://localhost:3000/entities/1/instances.json?");
        > myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
        > myDataSource.responseSchema = {
        > fields: ["url", "lock_version", "entity_url","details_url",
        > "links_url", { "status" : function(status) { "status" }}, {"title":
        > function(t){"title"}} , {"deadline": function(t){"deadline"}},
        > {"description":function(v){"description"}} ],
        > resultsList: "resources"
        > };
        >
        > myDataSource.sendRequest("test=1", oCallback);
        >
        >
        >
        >
        > --
        > Web database: http://www.myowndb.com
        > Free Software Developers Meeting: http://www.fosdem.org
        >
      • Satyam
        Sorry about the missinformation I provided. Thanks for the correction. Satyam ... From: y_lsmith To: ydn-javascript@yahoogroups.com Sent: Thursday, May 01,
        Message 3 of 12 , May 2, 2008
        • 0 Attachment
          Sorry about the missinformation I provided. Thanks for the correction.
           
          Satyam
           
          ----- Original Message -----
          From: y_lsmith
          Sent: Thursday, May 01, 2008 9:35 PM
          Subject: [ydn-javascript] Re: datasource: json format expected

          Raph,

          DataSource is capable of extracting values from nested structures.  However, it looks like you want to capture the collection of values for your columns 'status', 'title', 'deadline', and 'description'.  Keep in mind that DataTable doesn't support tree like row structures, but you could use a custom formatter to turn the array data into a single cell value.  I threw together this example page  to show how to do it.

          Hope this helps,
          Luke

          --- In ydn-javascript@yahoogroups.com, "Raphael Bauduin" <rblists@...> wrote:
          >
          > Hi,
          >
          > Is the data source component able to work with this json?
          >
          > { "length" : 3,
          > "resources": [
          > { "url": "http://localhost:3000/instances/5.json",
          > "lock_version": 0,
          > "entity_url": "htp://localhost:3000/entities/1.json",
          > "details_url": "http://localhost:3000/entities/1/details.json",
          > "links_url": "http://localhost:3000/instances/5/links.json",
          > "status": [
          > { "url": "http://localhost:3000/details/5/values/3.json",
          > "lock_version": 0,
          > "value": "On-hold"}
          > ],
          > "title": [
          > { "url": "http://localhost:3000/details/1/values/6.json",
          > "lock_version": 0, "value": "second test"}
          > ],
          > "deadline": [
          > { "url": "http://localhost:3000/details/4/values/3.json",
          > "lock_version": 0,
          > "value": "2008-05-01 15:35:50"}
          > ],
          > "description": [
          > { "url": "http://localhost:3000/details/2/values/7.json",
          > "lock_version": 0,
          > "value": "anoh er descrpition"}
          > ]
          > }
          > ]
          > }
          >
          > As you can see there are nested objects. I always get a failure, even
          > when I try with parser functions.
          > Here is the latest version of my code, thanks for any hint to solve the problem.
          >
          > Raph
          >
          >
          > var oCallback = {
          > success: function(oRequest,oResponse,oPayload) {
          > console.log('success');
          > },
          > failure: function(oRequest,oResponse,oPayload) {
          > console.log('failure');
          > },
          > scope:this
          > }
          >
          > var myDataSource = new
          > YAHOO.util.DataSource("http://localhost:3000/entities/1/instances.json?");
          > myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
          > myDataSource.responseSchema = {
          > fields: ["url", "lock_version", "entity_url","details_url",
          > "links_url", { "status" : function(status) { "status" }}, {"title":
          > function(t){"title"}} , {"deadlin": function(t){"deadline"}},
          > {"description":function(v){"description"}} ],
          > resultsList: "resources"
          > };
          >
          > myDataSource.sendRequest("test=1", oCallback);
          >
          >
          >
          >
          > --
          > Web database: http://www.myowndb.com
          > Free Software Developers Meeting: http://www.fosdem.org
          >


          No virus found in this incoming message.
          Checked by AVG.
          Version: 7.5.524 / Virus Database: 269.23.7/1408 - Release Date: 30/04/2008 18:10
        • Raphael Bauduin
          ... Hi Luke, thanks for taking a look at this! I will indeed look at a custom formatter once I can use the json, but I m still not there :( I ve looked closely
          Message 4 of 12 , May 2, 2008
          • 0 Attachment
            On Thu, May 1, 2008 at 9:35 PM, y_lsmith <lsmith@...> wrote:
            >
            > Raph,
            >
            > DataSource is capable of extracting values from nested structures. However,
            > it looks like you want to capture the collection of values for your columns
            > 'status', 'title', 'deadline', and 'description'. Keep in mind that
            > DataTable doesn't support tree like row structures, but you could use a
            > custom formatter to turn the array data into a single cell value. I threw
            > together this example page to show how to do it.

            Hi Luke,

            thanks for taking a look at this! I will indeed look at a custom
            formatter once I can use the json, but I'm still not there :(
            I've looked closely at your example, and simplified my code a lot. I'm
            now trying with this code, but still without success:

            myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
            myDataSource.responseSchema = {
            fields: ["url" ],
            resultsList: "resources"
            };

            I put a page with code consuming the json at http://www.raphinou.com/test.html
            There you can just copy and paste the javascript code displayed on the
            page in the firebug console, and you should get a failure.

            I hope you have the opportunity to take a look because I really don't
            see what I'm doing wrong here.

            Thanks

            Raph



            >
            > Hope this helps,
            > Luke
            >
            >
            >
            > --- In ydn-javascript@yahoogroups.com, "Raphael Bauduin" <rblists@...>
            > wrote:
            > >
            > > Hi,
            > >
            > > Is the data source component able to work with this json?
            > >
            > > { "length" : 3,
            > > "resources": [
            > > { "url": "http://localhost:3000/instances/5.json",
            > > "lock_version": 0,
            > > "entity_url": "http://localhost:3000/entities/1.json",
            > > "details_url": "http://localhost:3000/entities/1/details.json",
            > > "links_url": "http://localhost:3000/instances/5/links.json",
            > > "status": [
            > > { "url": "http://localhost:3000/details/5/values/3.json",
            > > "lock_version": 0,
            > > "value": "On-hold"}
            > > ],
            > > "title": [
            > > { "url": "http://localhost:3000/details/1/values/6.json",
            > > "lock_version": 0, "value": "second test"}
            > > ],
            > > "deadline": [
            > > { "url": "http://localhost:3000/details/4/values/3.json",
            > > "lock_version": 0,
            > > "value": "2008-05-01 15:35:50"}
            > > ],
            > > "description": [
            > > { "url": "http://localhost:3000/details/2/values/7.json",
            > > "lock_version": 0,
            > > "value": "another descrpition"}
            > > ]
            > > }
            > > ]
            > > }
            > >
            > > As you can see there are nested objects. I always get a failure, even
            > > when I try with parser functions.
            > > Here is the latest version of my code, thanks for any hint to solve the
            > problem.
            > >
            > > Raph
            > >
            > >
            > > var oCallback = {
            > > success: function(oRequest,oResponse,oPayload) {
            > > console.log('success');
            > > },
            > > failure: function(oRequest,oResponse,oPayload) {
            > > console.log('failure');
            > > },
            > > scope:this
            > > }
            > >
            > > var myDataSource = new
            > > YAHOO.util.DataSource("http://localhost:3000/entities/1/instances.json?");
            > > myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
            > > myDataSource.responseSchema = {
            > > fields: ["url", "lock_version", "entity_url","details_url",
            > > "links_url", { "status" : function(status) { "status" }}, {"title":
            > > function(t){"title"}} , {"deadline": function(t){"deadline"}},
            > > {"description":function(v){"description"}} ],
            > > resultsList: "resources"
            > > };
            > >
            > > myDataSource.sendRequest("test=1", oCallback);
            > >
            > >
            > >
            > >
            > > --
            > > Web database: http://www.myowndb.com
            > > Free Software Developers Meeting: http://www.fosdem.org
            > >
            >



            --
            Web database: http://www.myowndb.com
            Free Software Developers Meeting: http://www.fosdem.org
          • Satyam
            If you are including the JSON component, it will fail, if not, it will work. The DataSource comes with a JSON decoded which is somewhat more tolerant than the
            Message 5 of 12 , May 2, 2008
            • 0 Attachment
              If you are including the JSON component, it will fail, if not, it will work.
              The DataSource comes with a JSON decoded which is somewhat more tolerant
              than the standard. It will accept unquoted identifiers. The JSON component
              is stricter and won't take your JSON message because the first two
              identifiers, length and resources are not within quotes. So, either make
              sure to put quotes around all identifiers or don't load the JSON component
              and let the DataSource deal with it. I recomend the first one since,
              eventually, the DataSource will catch up with the standard and will also
              fail.

              Satyam

              ----- Original Message -----
              From: "Raphael Bauduin" <rblists@...>
              To: <ydn-javascript@yahoogroups.com>
              Sent: Friday, May 02, 2008 11:55 AM
              Subject: Re: [ydn-javascript] Re: datasource: json format expected


              > On Thu, May 1, 2008 at 9:35 PM, y_lsmith <lsmith@...> wrote:
              >>
              >> Raph,
              >>
              >> DataSource is capable of extracting values from nested structures.
              >> However,
              >> it looks like you want to capture the collection of values for your
              >> columns
              >> 'status', 'title', 'deadline', and 'description'. Keep in mind that
              >> DataTable doesn't support tree like row structures, but you could use a
              >> custom formatter to turn the array data into a single cell value. I
              >> threw
              >> together this example page to show how to do it.
              >
              > Hi Luke,
              >
              > thanks for taking a look at this! I will indeed look at a custom
              > formatter once I can use the json, but I'm still not there :(
              > I've looked closely at your example, and simplified my code a lot. I'm
              > now trying with this code, but still without success:
              >
              > myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
              > myDataSource.responseSchema = {
              > fields: ["url" ],
              > resultsList: "resources"
              > };
              >
              > I put a page with code consuming the json at
              > http://www.raphinou.com/test.html
              > There you can just copy and paste the javascript code displayed on the
              > page in the firebug console, and you should get a failure.
              >
              > I hope you have the opportunity to take a look because I really don't
              > see what I'm doing wrong here.
              >
              > Thanks
              >
              > Raph
              >
              >
              >
              >>
              >> Hope this helps,
              >> Luke
              >>
              >>
              >>
              >> --- In ydn-javascript@yahoogroups.com, "Raphael Bauduin" <rblists@...>
              >> wrote:
              >> >
              >> > Hi,
              >> >
              >> > Is the data source component able to work with this json?
              >> >
              >> > { "length" : 3,
              >> > "resources": [
              >> > { "url": "http://localhost:3000/instances/5.json",
              >> > "lock_version": 0,
              >> > "entity_url": "http://localhost:3000/entities/1.json",
              >> > "details_url": "http://localhost:3000/entities/1/details.json",
              >> > "links_url": "http://localhost:3000/instances/5/links.json",
              >> > "status": [
              >> > { "url": "http://localhost:3000/details/5/values/3.json",
              >> > "lock_version": 0,
              >> > "value": "On-hold"}
              >> > ],
              >> > "title": [
              >> > { "url": "http://localhost:3000/details/1/values/6.json",
              >> > "lock_version": 0, "value": "second test"}
              >> > ],
              >> > "deadline": [
              >> > { "url": "http://localhost:3000/details/4/values/3.json",
              >> > "lock_version": 0,
              >> > "value": "2008-05-01 15:35:50"}
              >> > ],
              >> > "description": [
              >> > { "url": "http://localhost:3000/details/2/values/7.json",
              >> > "lock_version": 0,
              >> > "value": "another descrpition"}
              >> > ]
              >> > }
              >> > ]
              >> > }
              >> >
              >> > As you can see there are nested objects. I always get a failure, even
              >> > when I try with parser functions.
              >> > Here is the latest version of my code, thanks for any hint to solve the
              >> problem.
              >> >
              >> > Raph
              >> >
              >> >
              >> > var oCallback = {
              >> > success: function(oRequest,oResponse,oPayload) {
              >> > console.log('success');
              >> > },
              >> > failure: function(oRequest,oResponse,oPayload) {
              >> > console.log('failure');
              >> > },
              >> > scope:this
              >> > }
              >> >
              >> > var myDataSource = new
              >> > YAHOO.util.DataSource("http://localhost:3000/entities/1/instances.json?");
              >> > myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
              >> > myDataSource.responseSchema = {
              >> > fields: ["url", "lock_version", "entity_url","details_url",
              >> > "links_url", { "status" : function(status) { "status" }}, {"title":
              >> > function(t){"title"}} , {"deadline": function(t){"deadline"}},
              >> > {"description":function(v){"description"}} ],
              >> > resultsList: "resources"
              >> > };
              >> >
              >> > myDataSource.sendRequest("test=1", oCallback);
              >> >
              >> >
              >> >
              >> >
              >> > --
              >> > Web database: http://www.myowndb.com
              >> > Free Software Developers Meeting: http://www.fosdem.org
              >> >
              >>
              >
              >
              >
              > --
              > Web database: http://www.myowndb.com
              > Free Software Developers Meeting: http://www.fosdem.org
              >
              > ------------------------------------
              >
              > Yahoo! Groups Links
              >
              >
              >
              >
              >
              > --
              > No virus found in this incoming message.
              > Checked by AVG.
              > Version: 7.5.524 / Virus Database: 269.23.7/1410 - Release Date:
              > 01/05/2008 17:30
              >
              >
            • Raphael Bauduin
              ... That s working indeed! Thanks Satyam and Luke for taking the time to help me!! Raph ... -- Web database: http://www.myowndb.com Free Software Developers
              Message 6 of 12 , May 2, 2008
              • 0 Attachment
                On Fri, May 2, 2008 at 12:29 PM, Satyam <satyam@...> wrote:
                > If you are including the JSON component, it will fail, if not, it will work.
                > The DataSource comes with a JSON decoded which is somewhat more tolerant
                > than the standard. It will accept unquoted identifiers. The JSON component
                > is stricter and won't take your JSON message because the first two
                > identifiers, length and resources are not within quotes. So, either make
                > sure to put quotes around all identifiers or don't load the JSON component
                > and let the DataSource deal with it. I recomend the first one since,
                > eventually, the DataSource will catch up with the standard and will also
                > fail.
                >

                That's working indeed!

                Thanks Satyam and Luke for taking the time to help me!!

                Raph



                >
                > Satyam
                >
                > ----- Original Message -----
                > From: "Raphael Bauduin" <rblists@...>
                >
                > To: <ydn-javascript@yahoogroups.com>
                >
                >
                > Sent: Friday, May 02, 2008 11:55 AM
                > Subject: Re: [ydn-javascript] Re: datasource: json format expected
                >
                >
                > > On Thu, May 1, 2008 at 9:35 PM, y_lsmith <lsmith@...> wrote:
                > >>
                > >> Raph,
                > >>
                > >> DataSource is capable of extracting values from nested structures.
                > >> However,
                > >> it looks like you want to capture the collection of values for your
                > >> columns
                > >> 'status', 'title', 'deadline', and 'description'. Keep in mind that
                > >> DataTable doesn't support tree like row structures, but you could use a
                > >> custom formatter to turn the array data into a single cell value. I
                > >> threw
                > >> together this example page to show how to do it.
                > >
                > > Hi Luke,
                > >
                > > thanks for taking a look at this! I will indeed look at a custom
                > > formatter once I can use the json, but I'm still not there :(
                > > I've looked closely at your example, and simplified my code a lot. I'm
                > > now trying with this code, but still without success:
                > >
                > > myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
                > > myDataSource.responseSchema = {
                > > fields: ["url" ],
                > > resultsList: "resources"
                > > };
                > >
                > > I put a page with code consuming the json at
                > > http://www.raphinou.com/test.html
                > > There you can just copy and paste the javascript code displayed on the
                > > page in the firebug console, and you should get a failure.
                > >
                > > I hope you have the opportunity to take a look because I really don't
                > > see what I'm doing wrong here.
                > >
                > > Thanks
                > >
                > > Raph
                > >
                > >
                > >
                > >>
                > >> Hope this helps,
                > >> Luke
                > >>
                > >>
                > >>
                > >> --- In ydn-javascript@yahoogroups.com, "Raphael Bauduin" <rblists@...>
                > >> wrote:
                > >> >
                > >> > Hi,
                > >> >
                > >> > Is the data source component able to work with this json?
                > >> >
                > >> > { "length" : 3,
                > >> > "resources": [
                > >> > { "url": "http://localhost:3000/instances/5.json",
                > >> > "lock_version": 0,
                > >> > "entity_url": "http://localhost:3000/entities/1.json",
                > >> > "details_url": "http://localhost:3000/entities/1/details.json",
                > >> > "links_url": "http://localhost:3000/instances/5/links.json",
                > >> > "status": [
                > >> > { "url": "http://localhost:3000/details/5/values/3.json",
                > >> > "lock_version": 0,
                > >> > "value": "On-hold"}
                > >> > ],
                > >> > "title": [
                > >> > { "url": "http://localhost:3000/details/1/values/6.json",
                > >> > "lock_version": 0, "value": "second test"}
                > >> > ],
                > >> > "deadline": [
                > >> > { "url": "http://localhost:3000/details/4/values/3.json",
                > >> > "lock_version": 0,
                > >> > "value": "2008-05-01 15:35:50"}
                > >> > ],
                > >> > "description": [
                > >> > { "url": "http://localhost:3000/details/2/values/7.json",
                > >> > "lock_version": 0,
                > >> > "value": "another descrpition"}
                > >> > ]
                > >> > }
                > >> > ]
                > >> > }
                > >> >
                > >> > As you can see there are nested objects. I always get a failure, even
                > >> > when I try with parser functions.
                > >> > Here is the latest version of my code, thanks for any hint to solve the
                > >> problem.
                > >> >
                > >> > Raph
                > >> >
                > >> >
                > >> > var oCallback = {
                > >> > success: function(oRequest,oResponse,oPayload) {
                > >> > console.log('success');
                > >> > },
                > >> > failure: function(oRequest,oResponse,oPayload) {
                > >> > console.log('failure');
                > >> > },
                > >> > scope:this
                > >> > }
                > >> >
                > >> > var myDataSource = new
                > >> > YAHOO.util.DataSource("http://localhost:3000/entities/1/instances.json?");
                > >> > myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
                > >> > myDataSource.responseSchema = {
                > >> > fields: ["url", "lock_version", "entity_url","details_url",
                > >> > "links_url", { "status" : function(status) { "status" }}, {"title":
                > >> > function(t){"title"}} , {"deadline": function(t){"deadline"}},
                > >> > {"description":function(v){"description"}} ],
                > >> > resultsList: "resources"
                > >> > };
                > >> >
                > >> > myDataSource.sendRequest("test=1", oCallback);
                > >> >
                > >> >
                > >> >
                > >> >
                > >> > --
                > >> > Web database: http://www.myowndb.com
                > >> > Free Software Developers Meeting: http://www.fosdem.org
                > >> >
                > >>
                > >
                > >
                > >
                > > --
                >
                > > Web database: http://www.myowndb.com
                > > Free Software Developers Meeting: http://www.fosdem.org
                > >
                > > ------------------------------------
                > >
                > > Yahoo! Groups Links
                > >
                > >
                > >
                > >
                > >
                > > --
                >
                > > No virus found in this incoming message.
                > > Checked by AVG.
                > > Version: 7.5.524 / Virus Database: 269.23.7/1410 - Release Date:
                > > 01/05/2008 17:30
                >
                > >
                > >
                >
                >
                > ------------------------------------
                >
                > Yahoo! Groups Links
                >
                >
                >
                >
                >
                >



                --
                Web database: http://www.myowndb.com
                Free Software Developers Meeting: http://www.fosdem.org
              Your message has been successfully submitted and would be delivered to recipients shortly.