Reputation: 249
I want to add a Array of object like
"identifiers": [
{
"primary": true
},
{
"primary": false
},
]
But the object inside array always need a name to create like
"identifiers": [
{
"IDENTIFIER": {
"primary": true
}
}
]
I used the following JSON code in config file,
"identifiers": {
"title": "Identifiers",
"type": "array",
"location": "body",
"items": {
"title": "Identifier Fields",
"type": "object",
"properties": {
"IDENTIFIER": {
"type": "object",
"properties": {
"primary": {
"title": "primary",
"required": true,
"type": "boolean",
"description": "",
"default": true
}
}
}
}
}
}
How to achieve this. Kindly help me.
Thanks in advance.
Upvotes: 0
Views: 82
Reputation: 249
Thanks for responses.
I have made a mistake by adding extra object parameter. I have fix it by removing the extra object like
"identifiers": {
"title": "Identifiers",
"type": "array",
"location": "body",
"items": {
"title": "Identifier Fields",
"type": "object",
"properties": {
"primary": {
"title": "primary",
"required": true,
"type": "boolean",
"description": "",
"default": true
}
}
}
}
Upvotes: 0
Reputation: 3580
you can do like this
data = {"identifiers": [
{
"primary": true
},
{
"primary": false
},
]};
for(i=0;i<data.identifiers.length;i++) {
obj = data.identifiers[i];
obj = {
"IDENTIFIER": {
"primary": obj.primary
}
}
//if you want all properties of obj means you have loop through it create them. go through this copying properties }
Upvotes: 0