Print service provided by iDogiCat: http://www.idogicat.com/
home logo





Home > IT > Programming > JSON

JSON

JSON: JavaScript Object Notation.

  • internet media type: application/json
  • file ext: .json

JSON is language independent although it comes from JavaScript. It's a lightweight data format and human readable. It has a smaller footprint than XML (for not having tags).

JSON is often used in RESTful web services, supported by many libraries and frameworks.

It's also useful in systems targeted to mobile phones due to its small footprint.

JSON has two basic structures:

  • Name/value pairs, separated with ':' and ends with ','. Names should be quoted with '"'
  • Ordered list of values: wrapped up with brackets

Data Types

  • String: in Unicode
  • Number
  • Boolean: true or false
  • Array
  • Object: wrapped up with curly brackets
  • null: empty

Examples

Basic data types:

{
    "type": "Cat",
    "weight":  5,
    "Fighter": true
}

Arrays:

{
    "scores": [5, 4, 3, 5],
    "animals": ["Dog", "Cat"]
}

More:

{
    "name": "Mimimao",
    "age": "10",
    "gender": "M",
    "address": {
        "street": "123 Wonderland",
        "city": "Tokyo",
        "country": "Japan",
        "postalCode": "135-0001"
    },
    "phoneNumbers": [
        {
            "type": "home",
            "number": "03-1111-1111"
        },
        {
            "type": "mobile",
            "number": "080-2222-2222"
        }
    ]
}