Array of objects using IODOCS

84 views Asked by At

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.

2

There are 2 answers

0
Raghavendra On

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 }

0
Raja On

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
                    }
                }
            }
}