how to get json object titles












0















I'm a new programmer , I know how to use dictionary/JSON to get the value of whatever you want like for example var x = {"name":jack,"age":20};

then x.name = jack



but what if I've a table that has been imported through an unknown EXCEL file and I just want to know the title of each column , how can i do that ?



for example



Var table = [{"id":0 , "name":jack,"age":25,"profession":student},{"id":1 , "name":nora,"age":22,"profession":student}]


i want to make a javascript function that can inform me with titles of each columns , the number of the columns
how can i do that ?










share|improve this question

























  • do note Var table = is invalid syntax, and both name:jack, and profession:student} is likely wrong too, strings must be enclosed in delimiters

    – CertainPerformance
    Nov 25 '18 at 23:37













  • should profession:student be profession:"student" ?

    – Dacre Denny
    Nov 25 '18 at 23:40











  • i fixed it thanks , correct me if iam not wrong but "profession":student is the right syntax

    – za002
    Nov 25 '18 at 23:42











  • Unless student is a variable, you are wrong :D Also, note that JavaScript, like most of the popular programming languages, is case-sensitive, and Var is not var. This is correct: var table = [{"id":0 , "name":"jack","age":25,"profession":"student"},{"id":1 , "name":"nora","age":22,"profession":"student"}]

    – Amadan
    Nov 25 '18 at 23:53











  • You can validate a json online here : jsonlint.com

    – Shim-Sao
    Nov 26 '18 at 0:39
















0















I'm a new programmer , I know how to use dictionary/JSON to get the value of whatever you want like for example var x = {"name":jack,"age":20};

then x.name = jack



but what if I've a table that has been imported through an unknown EXCEL file and I just want to know the title of each column , how can i do that ?



for example



Var table = [{"id":0 , "name":jack,"age":25,"profession":student},{"id":1 , "name":nora,"age":22,"profession":student}]


i want to make a javascript function that can inform me with titles of each columns , the number of the columns
how can i do that ?










share|improve this question

























  • do note Var table = is invalid syntax, and both name:jack, and profession:student} is likely wrong too, strings must be enclosed in delimiters

    – CertainPerformance
    Nov 25 '18 at 23:37













  • should profession:student be profession:"student" ?

    – Dacre Denny
    Nov 25 '18 at 23:40











  • i fixed it thanks , correct me if iam not wrong but "profession":student is the right syntax

    – za002
    Nov 25 '18 at 23:42











  • Unless student is a variable, you are wrong :D Also, note that JavaScript, like most of the popular programming languages, is case-sensitive, and Var is not var. This is correct: var table = [{"id":0 , "name":"jack","age":25,"profession":"student"},{"id":1 , "name":"nora","age":22,"profession":"student"}]

    – Amadan
    Nov 25 '18 at 23:53











  • You can validate a json online here : jsonlint.com

    – Shim-Sao
    Nov 26 '18 at 0:39














0












0








0


1






I'm a new programmer , I know how to use dictionary/JSON to get the value of whatever you want like for example var x = {"name":jack,"age":20};

then x.name = jack



but what if I've a table that has been imported through an unknown EXCEL file and I just want to know the title of each column , how can i do that ?



for example



Var table = [{"id":0 , "name":jack,"age":25,"profession":student},{"id":1 , "name":nora,"age":22,"profession":student}]


i want to make a javascript function that can inform me with titles of each columns , the number of the columns
how can i do that ?










share|improve this question
















I'm a new programmer , I know how to use dictionary/JSON to get the value of whatever you want like for example var x = {"name":jack,"age":20};

then x.name = jack



but what if I've a table that has been imported through an unknown EXCEL file and I just want to know the title of each column , how can i do that ?



for example



Var table = [{"id":0 , "name":jack,"age":25,"profession":student},{"id":1 , "name":nora,"age":22,"profession":student}]


i want to make a javascript function that can inform me with titles of each columns , the number of the columns
how can i do that ?







javascript arrays json list






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 25 '18 at 23:41







za002

















asked Nov 25 '18 at 23:36









za002za002

154




154













  • do note Var table = is invalid syntax, and both name:jack, and profession:student} is likely wrong too, strings must be enclosed in delimiters

    – CertainPerformance
    Nov 25 '18 at 23:37













  • should profession:student be profession:"student" ?

    – Dacre Denny
    Nov 25 '18 at 23:40











  • i fixed it thanks , correct me if iam not wrong but "profession":student is the right syntax

    – za002
    Nov 25 '18 at 23:42











  • Unless student is a variable, you are wrong :D Also, note that JavaScript, like most of the popular programming languages, is case-sensitive, and Var is not var. This is correct: var table = [{"id":0 , "name":"jack","age":25,"profession":"student"},{"id":1 , "name":"nora","age":22,"profession":"student"}]

    – Amadan
    Nov 25 '18 at 23:53











  • You can validate a json online here : jsonlint.com

    – Shim-Sao
    Nov 26 '18 at 0:39



















  • do note Var table = is invalid syntax, and both name:jack, and profession:student} is likely wrong too, strings must be enclosed in delimiters

    – CertainPerformance
    Nov 25 '18 at 23:37













  • should profession:student be profession:"student" ?

    – Dacre Denny
    Nov 25 '18 at 23:40











  • i fixed it thanks , correct me if iam not wrong but "profession":student is the right syntax

    – za002
    Nov 25 '18 at 23:42











  • Unless student is a variable, you are wrong :D Also, note that JavaScript, like most of the popular programming languages, is case-sensitive, and Var is not var. This is correct: var table = [{"id":0 , "name":"jack","age":25,"profession":"student"},{"id":1 , "name":"nora","age":22,"profession":"student"}]

    – Amadan
    Nov 25 '18 at 23:53











  • You can validate a json online here : jsonlint.com

    – Shim-Sao
    Nov 26 '18 at 0:39

















do note Var table = is invalid syntax, and both name:jack, and profession:student} is likely wrong too, strings must be enclosed in delimiters

– CertainPerformance
Nov 25 '18 at 23:37







do note Var table = is invalid syntax, and both name:jack, and profession:student} is likely wrong too, strings must be enclosed in delimiters

– CertainPerformance
Nov 25 '18 at 23:37















should profession:student be profession:"student" ?

– Dacre Denny
Nov 25 '18 at 23:40





should profession:student be profession:"student" ?

– Dacre Denny
Nov 25 '18 at 23:40













i fixed it thanks , correct me if iam not wrong but "profession":student is the right syntax

– za002
Nov 25 '18 at 23:42





i fixed it thanks , correct me if iam not wrong but "profession":student is the right syntax

– za002
Nov 25 '18 at 23:42













Unless student is a variable, you are wrong :D Also, note that JavaScript, like most of the popular programming languages, is case-sensitive, and Var is not var. This is correct: var table = [{"id":0 , "name":"jack","age":25,"profession":"student"},{"id":1 , "name":"nora","age":22,"profession":"student"}]

– Amadan
Nov 25 '18 at 23:53





Unless student is a variable, you are wrong :D Also, note that JavaScript, like most of the popular programming languages, is case-sensitive, and Var is not var. This is correct: var table = [{"id":0 , "name":"jack","age":25,"profession":"student"},{"id":1 , "name":"nora","age":22,"profession":"student"}]

– Amadan
Nov 25 '18 at 23:53













You can validate a json online here : jsonlint.com

– Shim-Sao
Nov 26 '18 at 0:39





You can validate a json online here : jsonlint.com

– Shim-Sao
Nov 26 '18 at 0:39












4 Answers
4






active

oldest

votes


















2














First of all, an object in JavaScript doesn't care if it was constructed out of JSON or not. So your object in JavaScript syntax will look like this:



const x = { name: 'jack', age: 20 };


If you now do Object.keys(x), you will get this:



[ 'name', 'age' ]


And Object.keys(table[0]) should be exactly what you want: the column names of your 'table'



[ 'name', 'age' ]





share|improve this answer































    1














    Object.keys(table[0])


    will give you the keys of the first row; presumably the other rows will behave and follow the pattern.






    share|improve this answer































      1














      You can get a list of the names of the properties of an object in javascript with this :



      Object.keys();


      Documentation here :



      https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys



      Response of a similar question here :



      Getting the object's property name






      share|improve this answer































        0














        Just iterate over object keys:



        for (var key in table[0]) {console.log(key);}


        or (will work in most modern browsers):



        Object.keys(table[0]).forEach(key => console.log(key));


        Don't forget to check if "table" has elements



        Also see other possible options






        share|improve this answer





















        • 2





          This is not recommended. Try executing Object.prototype.foo = "bar" before running your code for a nice surprise. If you are using for ... in to iterate over object keys, almost always you'll want to test .hasOwnProperty to rule out intruders.

          – Amadan
          Nov 25 '18 at 23:50











        • True. But I assume in this exact situation nothing is being overridden in Object. Iterating in foreach is just faster and works in old IEs. Here are examples of all techniques: hackernoon.com/…

          – Azee
          Nov 26 '18 at 0:17













        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%2f53473088%2fhow-to-get-json-object-titles%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        2














        First of all, an object in JavaScript doesn't care if it was constructed out of JSON or not. So your object in JavaScript syntax will look like this:



        const x = { name: 'jack', age: 20 };


        If you now do Object.keys(x), you will get this:



        [ 'name', 'age' ]


        And Object.keys(table[0]) should be exactly what you want: the column names of your 'table'



        [ 'name', 'age' ]





        share|improve this answer




























          2














          First of all, an object in JavaScript doesn't care if it was constructed out of JSON or not. So your object in JavaScript syntax will look like this:



          const x = { name: 'jack', age: 20 };


          If you now do Object.keys(x), you will get this:



          [ 'name', 'age' ]


          And Object.keys(table[0]) should be exactly what you want: the column names of your 'table'



          [ 'name', 'age' ]





          share|improve this answer


























            2












            2








            2







            First of all, an object in JavaScript doesn't care if it was constructed out of JSON or not. So your object in JavaScript syntax will look like this:



            const x = { name: 'jack', age: 20 };


            If you now do Object.keys(x), you will get this:



            [ 'name', 'age' ]


            And Object.keys(table[0]) should be exactly what you want: the column names of your 'table'



            [ 'name', 'age' ]





            share|improve this answer













            First of all, an object in JavaScript doesn't care if it was constructed out of JSON or not. So your object in JavaScript syntax will look like this:



            const x = { name: 'jack', age: 20 };


            If you now do Object.keys(x), you will get this:



            [ 'name', 'age' ]


            And Object.keys(table[0]) should be exactly what you want: the column names of your 'table'



            [ 'name', 'age' ]






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 25 '18 at 23:55









            BojiBoji

            787




            787

























                1














                Object.keys(table[0])


                will give you the keys of the first row; presumably the other rows will behave and follow the pattern.






                share|improve this answer




























                  1














                  Object.keys(table[0])


                  will give you the keys of the first row; presumably the other rows will behave and follow the pattern.






                  share|improve this answer


























                    1












                    1








                    1







                    Object.keys(table[0])


                    will give you the keys of the first row; presumably the other rows will behave and follow the pattern.






                    share|improve this answer













                    Object.keys(table[0])


                    will give you the keys of the first row; presumably the other rows will behave and follow the pattern.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 25 '18 at 23:44









                    AmadanAmadan

                    133k13146197




                    133k13146197























                        1














                        You can get a list of the names of the properties of an object in javascript with this :



                        Object.keys();


                        Documentation here :



                        https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys



                        Response of a similar question here :



                        Getting the object's property name






                        share|improve this answer




























                          1














                          You can get a list of the names of the properties of an object in javascript with this :



                          Object.keys();


                          Documentation here :



                          https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys



                          Response of a similar question here :



                          Getting the object's property name






                          share|improve this answer


























                            1












                            1








                            1







                            You can get a list of the names of the properties of an object in javascript with this :



                            Object.keys();


                            Documentation here :



                            https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys



                            Response of a similar question here :



                            Getting the object's property name






                            share|improve this answer













                            You can get a list of the names of the properties of an object in javascript with this :



                            Object.keys();


                            Documentation here :



                            https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys



                            Response of a similar question here :



                            Getting the object's property name







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Nov 25 '18 at 23:45









                            Shim-SaoShim-Sao

                            710414




                            710414























                                0














                                Just iterate over object keys:



                                for (var key in table[0]) {console.log(key);}


                                or (will work in most modern browsers):



                                Object.keys(table[0]).forEach(key => console.log(key));


                                Don't forget to check if "table" has elements



                                Also see other possible options






                                share|improve this answer





















                                • 2





                                  This is not recommended. Try executing Object.prototype.foo = "bar" before running your code for a nice surprise. If you are using for ... in to iterate over object keys, almost always you'll want to test .hasOwnProperty to rule out intruders.

                                  – Amadan
                                  Nov 25 '18 at 23:50











                                • True. But I assume in this exact situation nothing is being overridden in Object. Iterating in foreach is just faster and works in old IEs. Here are examples of all techniques: hackernoon.com/…

                                  – Azee
                                  Nov 26 '18 at 0:17


















                                0














                                Just iterate over object keys:



                                for (var key in table[0]) {console.log(key);}


                                or (will work in most modern browsers):



                                Object.keys(table[0]).forEach(key => console.log(key));


                                Don't forget to check if "table" has elements



                                Also see other possible options






                                share|improve this answer





















                                • 2





                                  This is not recommended. Try executing Object.prototype.foo = "bar" before running your code for a nice surprise. If you are using for ... in to iterate over object keys, almost always you'll want to test .hasOwnProperty to rule out intruders.

                                  – Amadan
                                  Nov 25 '18 at 23:50











                                • True. But I assume in this exact situation nothing is being overridden in Object. Iterating in foreach is just faster and works in old IEs. Here are examples of all techniques: hackernoon.com/…

                                  – Azee
                                  Nov 26 '18 at 0:17
















                                0












                                0








                                0







                                Just iterate over object keys:



                                for (var key in table[0]) {console.log(key);}


                                or (will work in most modern browsers):



                                Object.keys(table[0]).forEach(key => console.log(key));


                                Don't forget to check if "table" has elements



                                Also see other possible options






                                share|improve this answer















                                Just iterate over object keys:



                                for (var key in table[0]) {console.log(key);}


                                or (will work in most modern browsers):



                                Object.keys(table[0]).forEach(key => console.log(key));


                                Don't forget to check if "table" has elements



                                Also see other possible options







                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited Nov 26 '18 at 0:19

























                                answered Nov 25 '18 at 23:43









                                AzeeAzee

                                1,4841319




                                1,4841319








                                • 2





                                  This is not recommended. Try executing Object.prototype.foo = "bar" before running your code for a nice surprise. If you are using for ... in to iterate over object keys, almost always you'll want to test .hasOwnProperty to rule out intruders.

                                  – Amadan
                                  Nov 25 '18 at 23:50











                                • True. But I assume in this exact situation nothing is being overridden in Object. Iterating in foreach is just faster and works in old IEs. Here are examples of all techniques: hackernoon.com/…

                                  – Azee
                                  Nov 26 '18 at 0:17
















                                • 2





                                  This is not recommended. Try executing Object.prototype.foo = "bar" before running your code for a nice surprise. If you are using for ... in to iterate over object keys, almost always you'll want to test .hasOwnProperty to rule out intruders.

                                  – Amadan
                                  Nov 25 '18 at 23:50











                                • True. But I assume in this exact situation nothing is being overridden in Object. Iterating in foreach is just faster and works in old IEs. Here are examples of all techniques: hackernoon.com/…

                                  – Azee
                                  Nov 26 '18 at 0:17










                                2




                                2





                                This is not recommended. Try executing Object.prototype.foo = "bar" before running your code for a nice surprise. If you are using for ... in to iterate over object keys, almost always you'll want to test .hasOwnProperty to rule out intruders.

                                – Amadan
                                Nov 25 '18 at 23:50





                                This is not recommended. Try executing Object.prototype.foo = "bar" before running your code for a nice surprise. If you are using for ... in to iterate over object keys, almost always you'll want to test .hasOwnProperty to rule out intruders.

                                – Amadan
                                Nov 25 '18 at 23:50













                                True. But I assume in this exact situation nothing is being overridden in Object. Iterating in foreach is just faster and works in old IEs. Here are examples of all techniques: hackernoon.com/…

                                – Azee
                                Nov 26 '18 at 0:17







                                True. But I assume in this exact situation nothing is being overridden in Object. Iterating in foreach is just faster and works in old IEs. Here are examples of all techniques: hackernoon.com/…

                                – Azee
                                Nov 26 '18 at 0:17




















                                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%2f53473088%2fhow-to-get-json-object-titles%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

                                Ottavio Pratesi

                                Tricia Helfer

                                15 giugno