-1

In the official Java EE tutorial said that JSON defines six data types: string, number, object, array, true, false and null. Consider the following:

{
   "firstName": "Duke",
   "lastName": "Java",
   "age": 18,
   "streetAddress": "100 Internet Dr",
   "city": "JavaTown",
   "state": "JA",
   "postalCode": "12345",
   "phoneNumbers": [
      { "Mobile": "111-111-1111" },
      { "Home": "222-222-2222" }
   ]
}

From, for example, pair "firstName": "Duke" how we can define what's type of the value? As i understood type of the name it the name-value pair is string always.

  • possible duplicate of [What is JSON and why would I use it?](http://stackoverflow.com/questions/383692/what-is-json-and-why-would-i-use-it) – Songo Nov 23 '13 at 02:19

1 Answers1

1

Objects have the form:

{"key1": value1, "key2": value2, ...}

Keys must be strings. valueX can be any valid JSON "data type" (i.e. object, array, numbers, string, true, false, null).

http://json.org/ has a nice syntax diagram:


(source: json.org)

In your example, {"firstName": "Duke", "lastName": "Java", ...} is an object, "firstName" is a key of the object and "Duke" is one of the values, which is a string.

Community
  • 1
  • 1
Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143