I have the json object in the following format.
{
"from": {
"required": false,
"type": {
"name": {
"required": false,
"type": "String"
},
"email": {
"required": true,
"type": "String"
}
}
},
"to": {
"required": true,
"type": [
{
"name": {
"required": false,
"type": "String"
},
"email": {
"required": true,
"type": "String"
}
}
]
},
"subject": {
"required": true,
"type": "String"
},
"text": {
"required": true,
"type": "String"
},
"html": {
"required": true,
"type": "String"
}
}
In the above object contains multiple nested properties . now i want to push these objects to my array $scope.fieldsInfo=[]
.
I want to get array in the follwoing format.
$scope.fieldsInfo=[
{
"label" :from,
"required" :true,
"type" : [
{
"label" : name,
"type": "String",
"required": false
}
{
"label" : email,
"type": "String",
"required": false
}
]
},
{
"label" :to,
"required" :false,
"type" : [
{
"label" : name,
"type": "String",
"required": true
}
{
"label" : email,
"type": "String",
"required": false
}
]
},
{
"label" :subject,
"required" :true,
"type" :string
},
{
"label" :text,
"required" :true,
"type" :string
},
{
"label" :html,
"required" :true,
"type" :string
}
]
I tried the following code , but only label and required properties are accessing .
for (var prop in data) {
$scope.fieldsInfo.push({ "label": prop, "required": result.data.hasOwnProperty(prop) });
}