tags:

views:

53

answers:

2

I would like to know, whats the right structure for a list of objects in JSON.

We are using JAXB to convert the POJO's to JSON.

Here is the choices, Please direct me what is right.

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

or

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

If the first structure is right, what is the JAXB annotation I should use to get the structure right.

+3  A: 

The first one is invalid syntax. You cannot have object properties inside a plain array. The second one is right although it is not strict JSON. It's a relaxed form of JSON wherein quotes in string keys are omitted.

This site may help to learn about JSON and this site may help to validate JSON.

BalusC
+2  A: 

The second is correct:

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