Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSON Structure for List of Objects

Tags:

java

json

jaxb

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.

like image 444
Vanchinathan Chandrasekaran Avatar asked Oct 12 '10 15:10

Vanchinathan Chandrasekaran


People also ask

Can a JSON contain a list?

Similar to other programming languages, a JSON Array is a list of items surrounded in square brackets ([]). Each item in the array is separated by a comma.

What is [] and {} in JSON?

' { } ' used for Object and ' [] ' is used for Array in json.

Can JSON have an array of objects?

Yes, you can create an array of objects. Technically, a 2D array is valid JSON.


1 Answers

The second is almost correct:

{     "foos" : [{         "prop1":"value1",         "prop2":"value2"     }, {         "prop1":"value3",          "prop2":"value4"     }] } 
like image 129
Justin Niessner Avatar answered Sep 23 '22 06:09

Justin Niessner