JSON Syntax: Transmitting an array

Andreas Grech picture Andreas Grech · Jan 10, 2009 · Viewed 20.2k times · Source

A valid JSON Syntax is something of the kind:

{
  "username": "admin",
  "password": "123"
}

But what if I want to transmit an array of 'users' (given the example), instead of a single 'user' ?

Is the code below Valid JSON, according to the specifications?

[{
  "username": "admin",
  "password": "123"
}, {
  "username": "bbvb",
  "password": "sdfsdf"
}, {
  "username": "asd",
  "password": "222"
}]

And if not, what is the best way to transmit an array of values across with JSON? (And with 'best way', I mean syntactically)

Answer

Andrew Hare picture Andrew Hare · Jan 10, 2009

Yes, your example is valid JSON - that is exactly how you want to use an array.

Edit : Here is a good link on JSON and its usage.