Failed to parse Dialogflow response into AppResponse












2















I'm having an issue when I perform an array map prior to conv.ask. I'm getting an error related to a malformed JSON object, but as far as I can tell it should be valid.



const timetableCells = timetable.Trains.map((item) => {
return {
cells: [item.Line, item.Destination, item.Car, item.Min],
}
})

conv.ask(new Table({
title: `Rail Timetable for ${station}`,
subtitle: 'Timetable as of x date',
image: new Image({
url: 'http://google.com/image.png',
alt: 'Logo'
}),
columns: [
{
header: 'Line',
align: 'LEADING'
},
{
header: 'Destination',
align: 'LEADING'
},
{
header: 'Car',
align: 'LEADING'
},
{
header: 'Arrival',
align: 'LEADING'
},
],
rows: timetableCells,
buttons: new Button({
title: 'Button Title',
url: 'https://github.com/actions-on-google'
})
}))


This is what timetable looks like:



{"Trains":[{"Car":"8","Destination":"Glenmont","DestinationCode":"B11","DestinationName":"Glenmont","Group":"1","Line":"RD","LocationCode":"B09","LocationName":"Forest Glen","Min":"9"},{"Car":"8","Destination":"Glenmont","DestinationCode":"B11","DestinationName":"Glenmont","Group":"1","Line":"RD","LocationCode":"B09","LocationName":"Forest Glen","Min":"18"},{"Car":"8","Destination":"Glenmont","DestinationCode":"B11","DestinationName":"Glenmont","Group":"1","Line":"RD","LocationCode":"B09","LocationName":"Forest Glen","Min":"36"},{"Car":"8","Destination":"Shady Gr","DestinationCode":"A15","DestinationName":"Shady Grove","Group":"2","Line":"RD","LocationCode":"B09","LocationName":"Forest Glen","Min":""}]}


If I log timetableCells I have an array that looks like this, and I'm assigning it to rows inside of conv.ask which should be equal to what Google Assistant is expecting according to their documentation.



[ { cells: ['1', '2', '3', '4'] }, { cells: ['1', '2', '3', '4'] } ]


If I stringify the JSON object I'm passing to conv.ask it looks correct:



JSON.parse("{"title":"Rail Timetable for Farragut North","subtitle":"Timetable as of x date","columns":[{"header":"Line","align":"LEADING"},{"header":"Destination","align":"LEADING"},{"header":"Car","align":"LEADING"},{"header":"Arrival","align":"LEADING"}],"rows":[{"cells":["RD","Glenmont","8",""]},{"cells":["RD","Shady Gr","8",""]}]}")


Where am I going wrong here? I know this line is the one causing the issue as I can replace it and it works correctly. The debugger points to a JSON validation error but I can't seem to see it.










share|improve this question

























  • Can you provide sample of how your data looks like?

    – sai.raj
    Nov 25 '18 at 4:58











  • @sai.raj Are you referring to the data payload from timetable? If so I've updated the original post.

    – James Ives
    Nov 25 '18 at 12:08


















2















I'm having an issue when I perform an array map prior to conv.ask. I'm getting an error related to a malformed JSON object, but as far as I can tell it should be valid.



const timetableCells = timetable.Trains.map((item) => {
return {
cells: [item.Line, item.Destination, item.Car, item.Min],
}
})

conv.ask(new Table({
title: `Rail Timetable for ${station}`,
subtitle: 'Timetable as of x date',
image: new Image({
url: 'http://google.com/image.png',
alt: 'Logo'
}),
columns: [
{
header: 'Line',
align: 'LEADING'
},
{
header: 'Destination',
align: 'LEADING'
},
{
header: 'Car',
align: 'LEADING'
},
{
header: 'Arrival',
align: 'LEADING'
},
],
rows: timetableCells,
buttons: new Button({
title: 'Button Title',
url: 'https://github.com/actions-on-google'
})
}))


This is what timetable looks like:



{"Trains":[{"Car":"8","Destination":"Glenmont","DestinationCode":"B11","DestinationName":"Glenmont","Group":"1","Line":"RD","LocationCode":"B09","LocationName":"Forest Glen","Min":"9"},{"Car":"8","Destination":"Glenmont","DestinationCode":"B11","DestinationName":"Glenmont","Group":"1","Line":"RD","LocationCode":"B09","LocationName":"Forest Glen","Min":"18"},{"Car":"8","Destination":"Glenmont","DestinationCode":"B11","DestinationName":"Glenmont","Group":"1","Line":"RD","LocationCode":"B09","LocationName":"Forest Glen","Min":"36"},{"Car":"8","Destination":"Shady Gr","DestinationCode":"A15","DestinationName":"Shady Grove","Group":"2","Line":"RD","LocationCode":"B09","LocationName":"Forest Glen","Min":""}]}


If I log timetableCells I have an array that looks like this, and I'm assigning it to rows inside of conv.ask which should be equal to what Google Assistant is expecting according to their documentation.



[ { cells: ['1', '2', '3', '4'] }, { cells: ['1', '2', '3', '4'] } ]


If I stringify the JSON object I'm passing to conv.ask it looks correct:



JSON.parse("{"title":"Rail Timetable for Farragut North","subtitle":"Timetable as of x date","columns":[{"header":"Line","align":"LEADING"},{"header":"Destination","align":"LEADING"},{"header":"Car","align":"LEADING"},{"header":"Arrival","align":"LEADING"}],"rows":[{"cells":["RD","Glenmont","8",""]},{"cells":["RD","Shady Gr","8",""]}]}")


Where am I going wrong here? I know this line is the one causing the issue as I can replace it and it works correctly. The debugger points to a JSON validation error but I can't seem to see it.










share|improve this question

























  • Can you provide sample of how your data looks like?

    – sai.raj
    Nov 25 '18 at 4:58











  • @sai.raj Are you referring to the data payload from timetable? If so I've updated the original post.

    – James Ives
    Nov 25 '18 at 12:08
















2












2








2








I'm having an issue when I perform an array map prior to conv.ask. I'm getting an error related to a malformed JSON object, but as far as I can tell it should be valid.



const timetableCells = timetable.Trains.map((item) => {
return {
cells: [item.Line, item.Destination, item.Car, item.Min],
}
})

conv.ask(new Table({
title: `Rail Timetable for ${station}`,
subtitle: 'Timetable as of x date',
image: new Image({
url: 'http://google.com/image.png',
alt: 'Logo'
}),
columns: [
{
header: 'Line',
align: 'LEADING'
},
{
header: 'Destination',
align: 'LEADING'
},
{
header: 'Car',
align: 'LEADING'
},
{
header: 'Arrival',
align: 'LEADING'
},
],
rows: timetableCells,
buttons: new Button({
title: 'Button Title',
url: 'https://github.com/actions-on-google'
})
}))


This is what timetable looks like:



{"Trains":[{"Car":"8","Destination":"Glenmont","DestinationCode":"B11","DestinationName":"Glenmont","Group":"1","Line":"RD","LocationCode":"B09","LocationName":"Forest Glen","Min":"9"},{"Car":"8","Destination":"Glenmont","DestinationCode":"B11","DestinationName":"Glenmont","Group":"1","Line":"RD","LocationCode":"B09","LocationName":"Forest Glen","Min":"18"},{"Car":"8","Destination":"Glenmont","DestinationCode":"B11","DestinationName":"Glenmont","Group":"1","Line":"RD","LocationCode":"B09","LocationName":"Forest Glen","Min":"36"},{"Car":"8","Destination":"Shady Gr","DestinationCode":"A15","DestinationName":"Shady Grove","Group":"2","Line":"RD","LocationCode":"B09","LocationName":"Forest Glen","Min":""}]}


If I log timetableCells I have an array that looks like this, and I'm assigning it to rows inside of conv.ask which should be equal to what Google Assistant is expecting according to their documentation.



[ { cells: ['1', '2', '3', '4'] }, { cells: ['1', '2', '3', '4'] } ]


If I stringify the JSON object I'm passing to conv.ask it looks correct:



JSON.parse("{"title":"Rail Timetable for Farragut North","subtitle":"Timetable as of x date","columns":[{"header":"Line","align":"LEADING"},{"header":"Destination","align":"LEADING"},{"header":"Car","align":"LEADING"},{"header":"Arrival","align":"LEADING"}],"rows":[{"cells":["RD","Glenmont","8",""]},{"cells":["RD","Shady Gr","8",""]}]}")


Where am I going wrong here? I know this line is the one causing the issue as I can replace it and it works correctly. The debugger points to a JSON validation error but I can't seem to see it.










share|improve this question
















I'm having an issue when I perform an array map prior to conv.ask. I'm getting an error related to a malformed JSON object, but as far as I can tell it should be valid.



const timetableCells = timetable.Trains.map((item) => {
return {
cells: [item.Line, item.Destination, item.Car, item.Min],
}
})

conv.ask(new Table({
title: `Rail Timetable for ${station}`,
subtitle: 'Timetable as of x date',
image: new Image({
url: 'http://google.com/image.png',
alt: 'Logo'
}),
columns: [
{
header: 'Line',
align: 'LEADING'
},
{
header: 'Destination',
align: 'LEADING'
},
{
header: 'Car',
align: 'LEADING'
},
{
header: 'Arrival',
align: 'LEADING'
},
],
rows: timetableCells,
buttons: new Button({
title: 'Button Title',
url: 'https://github.com/actions-on-google'
})
}))


This is what timetable looks like:



{"Trains":[{"Car":"8","Destination":"Glenmont","DestinationCode":"B11","DestinationName":"Glenmont","Group":"1","Line":"RD","LocationCode":"B09","LocationName":"Forest Glen","Min":"9"},{"Car":"8","Destination":"Glenmont","DestinationCode":"B11","DestinationName":"Glenmont","Group":"1","Line":"RD","LocationCode":"B09","LocationName":"Forest Glen","Min":"18"},{"Car":"8","Destination":"Glenmont","DestinationCode":"B11","DestinationName":"Glenmont","Group":"1","Line":"RD","LocationCode":"B09","LocationName":"Forest Glen","Min":"36"},{"Car":"8","Destination":"Shady Gr","DestinationCode":"A15","DestinationName":"Shady Grove","Group":"2","Line":"RD","LocationCode":"B09","LocationName":"Forest Glen","Min":""}]}


If I log timetableCells I have an array that looks like this, and I'm assigning it to rows inside of conv.ask which should be equal to what Google Assistant is expecting according to their documentation.



[ { cells: ['1', '2', '3', '4'] }, { cells: ['1', '2', '3', '4'] } ]


If I stringify the JSON object I'm passing to conv.ask it looks correct:



JSON.parse("{"title":"Rail Timetable for Farragut North","subtitle":"Timetable as of x date","columns":[{"header":"Line","align":"LEADING"},{"header":"Destination","align":"LEADING"},{"header":"Car","align":"LEADING"},{"header":"Arrival","align":"LEADING"}],"rows":[{"cells":["RD","Glenmont","8",""]},{"cells":["RD","Shady Gr","8",""]}]}")


Where am I going wrong here? I know this line is the one causing the issue as I can replace it and it works correctly. The debugger points to a JSON validation error but I can't seem to see it.







javascript json dialogflow actions-on-google






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 25 '18 at 13:02







James Ives

















asked Nov 24 '18 at 21:41









James IvesJames Ives

1,79811433




1,79811433













  • Can you provide sample of how your data looks like?

    – sai.raj
    Nov 25 '18 at 4:58











  • @sai.raj Are you referring to the data payload from timetable? If so I've updated the original post.

    – James Ives
    Nov 25 '18 at 12:08





















  • Can you provide sample of how your data looks like?

    – sai.raj
    Nov 25 '18 at 4:58











  • @sai.raj Are you referring to the data payload from timetable? If so I've updated the original post.

    – James Ives
    Nov 25 '18 at 12:08



















Can you provide sample of how your data looks like?

– sai.raj
Nov 25 '18 at 4:58





Can you provide sample of how your data looks like?

– sai.raj
Nov 25 '18 at 4:58













@sai.raj Are you referring to the data payload from timetable? If so I've updated the original post.

– James Ives
Nov 25 '18 at 12:08







@sai.raj Are you referring to the data payload from timetable? If so I've updated the original post.

– James Ives
Nov 25 '18 at 12:08














2 Answers
2






active

oldest

votes


















3














This took a really long time for me to figure out, and it's weird that a different error wasn't thrown here. It was obvious that the data in the rows needed to match the amount of headers in the table, however what wasn't obvious was that the strings cannot be empty, otherwise you'll get a parsing error.



There were cases where some values were returned as empty strings from my API response which was causing the problem. Changing the code to the following fixed the issue as it ensures that they'll never be empty strings.



const timetableCells = timetable.Trains.map((item) => {
return {
cells: [item.Line || "N/A", item.Destination || "N/A", item.Car || "TBD", item.Min || "TDB"],
}
})





share|improve this answer

































    0














    I have just resolved very similar issue. The array that you are assigning to rows and cells has to contain Strings only. In a situation, where those are numbers, the 'failed to parse DialogFlow response int AppResponse' will happen.






    share|improve this answer
























    • They are all strings, I've updated the original post with sample data.

      – James Ives
      Nov 25 '18 at 12:24











    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53462614%2ffailed-to-parse-dialogflow-response-into-appresponse%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    This took a really long time for me to figure out, and it's weird that a different error wasn't thrown here. It was obvious that the data in the rows needed to match the amount of headers in the table, however what wasn't obvious was that the strings cannot be empty, otherwise you'll get a parsing error.



    There were cases where some values were returned as empty strings from my API response which was causing the problem. Changing the code to the following fixed the issue as it ensures that they'll never be empty strings.



    const timetableCells = timetable.Trains.map((item) => {
    return {
    cells: [item.Line || "N/A", item.Destination || "N/A", item.Car || "TBD", item.Min || "TDB"],
    }
    })





    share|improve this answer






























      3














      This took a really long time for me to figure out, and it's weird that a different error wasn't thrown here. It was obvious that the data in the rows needed to match the amount of headers in the table, however what wasn't obvious was that the strings cannot be empty, otherwise you'll get a parsing error.



      There were cases where some values were returned as empty strings from my API response which was causing the problem. Changing the code to the following fixed the issue as it ensures that they'll never be empty strings.



      const timetableCells = timetable.Trains.map((item) => {
      return {
      cells: [item.Line || "N/A", item.Destination || "N/A", item.Car || "TBD", item.Min || "TDB"],
      }
      })





      share|improve this answer




























        3












        3








        3







        This took a really long time for me to figure out, and it's weird that a different error wasn't thrown here. It was obvious that the data in the rows needed to match the amount of headers in the table, however what wasn't obvious was that the strings cannot be empty, otherwise you'll get a parsing error.



        There were cases where some values were returned as empty strings from my API response which was causing the problem. Changing the code to the following fixed the issue as it ensures that they'll never be empty strings.



        const timetableCells = timetable.Trains.map((item) => {
        return {
        cells: [item.Line || "N/A", item.Destination || "N/A", item.Car || "TBD", item.Min || "TDB"],
        }
        })





        share|improve this answer















        This took a really long time for me to figure out, and it's weird that a different error wasn't thrown here. It was obvious that the data in the rows needed to match the amount of headers in the table, however what wasn't obvious was that the strings cannot be empty, otherwise you'll get a parsing error.



        There were cases where some values were returned as empty strings from my API response which was causing the problem. Changing the code to the following fixed the issue as it ensures that they'll never be empty strings.



        const timetableCells = timetable.Trains.map((item) => {
        return {
        cells: [item.Line || "N/A", item.Destination || "N/A", item.Car || "TBD", item.Min || "TDB"],
        }
        })






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 25 '18 at 13:20

























        answered Nov 25 '18 at 13:11









        James IvesJames Ives

        1,79811433




        1,79811433

























            0














            I have just resolved very similar issue. The array that you are assigning to rows and cells has to contain Strings only. In a situation, where those are numbers, the 'failed to parse DialogFlow response int AppResponse' will happen.






            share|improve this answer
























            • They are all strings, I've updated the original post with sample data.

              – James Ives
              Nov 25 '18 at 12:24
















            0














            I have just resolved very similar issue. The array that you are assigning to rows and cells has to contain Strings only. In a situation, where those are numbers, the 'failed to parse DialogFlow response int AppResponse' will happen.






            share|improve this answer
























            • They are all strings, I've updated the original post with sample data.

              – James Ives
              Nov 25 '18 at 12:24














            0












            0








            0







            I have just resolved very similar issue. The array that you are assigning to rows and cells has to contain Strings only. In a situation, where those are numbers, the 'failed to parse DialogFlow response int AppResponse' will happen.






            share|improve this answer













            I have just resolved very similar issue. The array that you are assigning to rows and cells has to contain Strings only. In a situation, where those are numbers, the 'failed to parse DialogFlow response int AppResponse' will happen.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 25 '18 at 6:29









            NevermelticeNevermeltice

            11




            11













            • They are all strings, I've updated the original post with sample data.

              – James Ives
              Nov 25 '18 at 12:24



















            • They are all strings, I've updated the original post with sample data.

              – James Ives
              Nov 25 '18 at 12:24

















            They are all strings, I've updated the original post with sample data.

            – James Ives
            Nov 25 '18 at 12:24





            They are all strings, I've updated the original post with sample data.

            – James Ives
            Nov 25 '18 at 12:24


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53462614%2ffailed-to-parse-dialogflow-response-into-appresponse%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Futebolista

            Feedback on college project

            Albești (Vaslui)