Quantcast
Channel: Mockaroo Community Forum - Latest posts
Viewing all articles
Browse latest Browse all 2665

Across an array of data, how to require a particular value appear once?

$
0
0

I am am trying to generate data such as the following

[{
    "id": 1,
    "company": "Doogle",
    "contacts": [{ 
        "primary": true,
        "first_name": "John",
        "last_name": "Doe"
    }]
},
{
    "id": 2,
    "company": "Bahoo",
    "contacts": [{ 
        "primary": false,
        "first_name": "Peter",
        "last_name": "Drake"
    },
    { 
        "primary": true,
        "first_name": "Jane",
        "last_name": "Smith"
    }]
}]

Contacts is an array of objects, how do I enforce the rule that one and only one contact can be primary and there must be at least one primary contact?


Viewing all articles
Browse latest Browse all 2665

Trending Articles