Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between '{' and '[' when formatting JSON object

Tags:

json

Is there any difference between '{' and '[' when formatting a JSON object?

like image 306
Clarence Avatar asked Jun 15 '12 06:06

Clarence


People also ask

What is [] and {} in JSON?

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

What is the difference between JSON object and JSONArray?

JSONObject and JSONArray are the two common classes usually available in most of the JSON processing libraries. A JSONObject stores unordered key-value pairs, much like a Java Map implementation. A JSONArray, on the other hand, is an ordered sequence of values much like a List or a Vector in Java.

What is the difference between an array and JSON How do they handle store data?

JSON Syntax JSON defines only two data structures: objects and arrays. An object is a set of name-value pairs, and an array is a list of values. JSON defines seven value types: string, number, object, array, true, false, and null.

Does element order matter in JSON?

From json.org "An object is an unordered set of name/value pairs." You should write your JSON processor so that order doesn't matter.


2 Answers

Yep one {...} is used to define a single object, while the other [...] is used to define a sequence of either objects, values or lists ...

objects are defined as such {key:object or list or value , ...} list ares nothing more than a sequence of either objects or lists or values, [objects or list or values, ... ]...

[{'value':1}, {'values':[1,2,3,3, {'a':'a', 'b':'b'}]}, 2, 3, 4]

like image 143
Samy Vilar Avatar answered Oct 06 '22 08:10

Samy Vilar


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

Like

var sampleObj = {                 a:1,                 b:'ab'                 };   var sampleArr = [1,'ab',4]; 
like image 31
Jitender Mahlawat Avatar answered Oct 06 '22 07:10

Jitender Mahlawat