I searched here get few related posts found but not helpful. I created one json file it has some text i want to append some more json in that using javascript(JSON stored in locally).
I have json file like this:
{ "Home": [ "a", "b", "c" ] }
i want to include this text "Log": 1
want to achieve like this,
{ "Home": [ "a", "b", "c" ], "Log": 1 }
Now I have like this in my json file(currently i have but json format is not correct)
{ "Home": [ "a", "b", "c" ] }
{ "Log": 1 }
$.getJSON('myfile.json', function(data) {
alert("success");
}.error(function(data){
alert(JSON.stringify(data));
});
this returns parser error. I know the JSON format is wrong. Please guide me to create a correct JSON format.
var a = JSON.stringify(homeicons);{ "Home": [ "a", "b", "c" ], "Log": 1 }(a) or[{ "Home": [ "a", "b", "c" ] } , { "Log": 1 }](b), you can't just append data to a json string and get a working json string. If you go with (b) you can achieve (a) withvar array = /* data from (b) */; var result = {}; $.extend.apply($, [{}] + array);;