1

I'm designing some REST style API endpoints that need to GET/POST (get/add) an array of objects.

Is there a strong reason to go with a format like:

{"Objects" : [{"Field1:Val1","Field2:Val2"},{"Field1:Val1","Field2:Val2"}]}

vs. omitting the top level "Objects" and just using the following instead?

[{"Field1:Val1","Field2:Val2"},{"Field1:Val1","Field2:Val2"}]
1
  • it allow you to add some extra data that has nothing to do in the array. With the first one you can use the same format for all your response, so you can use the same parser/logic to retrieve the data. Commented Feb 12, 2016 at 15:56

1 Answer 1

1

What is important, is that your data must be structured.

With {"Objects" : [{"Field1:Val1","Field2:Val2"},{"Field1:Val1","Field2:Val2"}]} you will be able to add other type of object that have not the same structure of {"Field1:Val1","Field2:Val2"}

For instance : {"firstname":"Tata", "lastname":"Toto","objects" : [{"name":"hammer","nb":4},{"name":"screw","nb":5}]}

So here your structure is :

firstname : string 
lastname : string 
objects : 
    name : string
    nb : int

If you use [{"Field1:Val1","Field2:Val2"},{"Field1:Val1","Field2:Val2"}], we expect that in your array, the elements represent the same type of data.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.