Home JSON vs. JavaScript object array. Why is the second approach different in result than the first? And how to achieve this?
 I know this is NOT a valid JSON, but when I declare this as variable directly within my code, then I can use it as an object. now I would like to store the same information into a file "table.data.js". the file then looks like: (the inner of BEGIN and END) //BEGIN { users: [{ person: { firstName: "Garry", lastName: "Finch" }, jobTitle: "Front End Technical Lead", twitter: "gazraa" }, { person: { firstName: "Hans", lastName: "Wurst" }, jobTitle: "Photographer", twitter: "photobasics" }, { person: { firstName: "Paul", lastName: "Stark" }, jobTitle: "LEGO Geek", twitter: "minifigures" }] } //END then I have tried different ways to read this file $.ajax({ contentType: "application/json; charset=utf-8", url: "Content/modules/Controls/table/table.data.js", data: "{}", dataType: "json", success: function(data) { var json = data; console.log(json); } }); then tried with$.get and $.getScript in any case the result would be not the same object //var jqxhr =$.get("Content/modules/Controls/table/table.data.js", function () { var jqxhr = \$.getScript("Content/modules/Controls/table/table.data.js", function (data, textStatus, jqxhr) { console.log("success"); }).done(function (data) { console.log(data); testdata = JSON.stringify(data); console.log(testdata); }).fail(function () { console.log("error"); }).always(function () { console.log("finished"); }); The result would never be the same object. I am only able to log the data as "plain" text into console. I guess this is a small step for some with knowledge, but actually for me a book with seven seals. EDIT: Thanks for all the responses. In summary that means, it is NOT possible to load the external data, store it in a variable like "mydata" and then work the same way as declaring it directly within the code? I will change the data to a valid JSON then. Then I would give @Quentin the medal for the shortest precise answer. But,thanks all for your clarification.