I have following data as a JSON in one variable which I am building in one controller. I can access this json data in other controller using factory/service. Now I want to modify this json data as like output json data.
Input Json
[
{
"text":"Identity",
"checked":true,
"timestamp":1435862483093
},
{
"text":"Calendar",
"checked":true,
"timestamp":1435862483443
},
]
Output :
{
"myname":{
"Facebook":{
"trackdata":[
{
"text":"Identity",
"checked":true,
"timestamp":1435862483093
},
{
"text":"Calendar",
"checked":true,
"timestamp":1435862483443
}
],
"selecteddata":[
{
"text":"Identity",
"checked":true,
"timestamp":1435862483093
},
{
"text":"Calendar",
"checked":true,
"timestamp":1435862483443
}
]
}
}
}
What am I am trying :
var trackdata = JSON.stringify(DataService.getTrackedData());
var selecteddata = JSON.stringify(DataService.getSelectedData());
var userJson = {};
userJson["trackdata"] = trackdata;
userJson["selecteddata"] = selecteddata;
userJson["Facebook"] = ???
userJson["myname"] = ???
What Can I write in last lines. The reason I put like is this in future "myname" and "Facebook" will be as per user input.
Update : 2
pmApp.controller('FooterController', function ($scope, $state, DataService) {
$scope.infunc = function () {
console.log("Username : " + DataService.username);
console.log("Application Name : " + DataService.applicationName);
var username = DataService.username;
var applicationName = DataService.username;
$scope.outputJson = {
username: {
applicationName: {
"trackdata": DataService.getTrackedData(),
"selecteddata": DataService.getSelectedData()
}
}
}
/* $scope.outputJson.myname.Facebook.trackdata = ;
$scope.outputJson.myname.Facebook.selecteddata = DataService.getSelectedData();*/
console.log(JSON.stringify($scope.outputJson));
};
});
It gives me output like this :
"username":{
"applicationName":{
"trackdata":[
Instead of username and applicationName it should print actual value of those variable. Can you please tell me what I am doing wrong here.
Thanks in advance.
Any help would be appreciated.