JSON Structure for List of Objects

The first example from your question,

foos: [
    foo: { ... },
    foo: { ... }
]

is in invalid syntax. You cannot have object properties inside a plain array.

The second example from your question,

foos: [
    { ... },
    { ... }
]

is right although it is not strict JSON. It's a relaxed form of JSON wherein quotes in string keys are omitted.

Following is the correct one when you want to obey strict JSON:

"foos": [
    { ... },
    { ... }
]

This "Mastering JSON" tutorial by Patrick Hunlock, may help to learn about JSON and this site may help to validate JSON.


The second is almost correct:

{
    "foos" : [{
        "prop1":"value1",
        "prop2":"value2"
    }, {
        "prop1":"value3", 
        "prop2":"value4"
    }]
}

Tags:

Java

Json

Jaxb