9

What is the JSON (JavaScript Object Notation) format?

vvvvv
  • 25,404
  • 19
  • 49
  • 81
yesraaj
  • 46,370
  • 69
  • 194
  • 251
  • 19
    I typed "JSON" into Google and the first 4 hits where highly relevant. – Paul Tomblin Nov 13 '08 at 13:50
  • Yeh, a bit lazy on the OPs part... – Gordon Thompson Nov 13 '08 at 13:53
  • 9
    The question generates great answers though. Next time stackoverflow could be in one of those highly relevant top 4 hits on google. – Mendelt Nov 13 '08 at 14:01
  • 5
    Lazy yes, but it seems like it's a legitimate item to be on here. – Brian Knoblauch Nov 13 '08 at 14:06
  • 9
    Except that the best answer is actually just a cut-n-paste from one of those (more legitimate?) top-fours. – Kev Nov 13 '08 at 14:07
  • 1
    I wrote the source at the end of the information. Most of answer of general question are cut and past. In this thread, I can see Wikipedia copy and past too ;) ...that's life. – Patrick Desjardins Nov 13 '08 at 14:08
  • **See also:** This question has an answer here [https://stackoverflow.com/questions/383692/what-is-json-and-why-would-i-use-it](https://stackoverflow.com/questions/383692/what-is-json-and-why-would-i-use-it) – dreftymac Nov 23 '19 at 22:36

6 Answers6

48

JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language, Standard ECMA-262 3rd Edition - December 1999. JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language.

Ref.: json.org

An object is an unordered set of name/value pairs. An object begins with { (left brace) and ends with } (right brace). Each name is followed by : (colon) and the name/value pairs are separated by , (comma).

alt text
(source: json.org)

An array is an ordered collection of values. An array begins with [ (left bracket) and ends with ] (right bracket). Values are separated by , (comma).

alt text
(source: json.org)

A value can be a string in double quotes, or a number, or true or false or null, or an object or an array. These structures can be nested.

alt text
(source: json.org)

A string is a collection of zero or more Unicode characters, wrapped in double quotes, using backslash escapes. A character is represented as a single character string. A string is very much like a C or Java string.

alt text
(source: json.org)

A number is very much like a C or Java number, except that the octal and hexadecimal formats are not used. alt text
(source: json.org)

Here is an example:

{
    "menu": {
        "id": "file",
        "value": "File",
        "popup": {
            "menuitem": [{
                "onclick": "CreateNewDoc()"
            }, {
                "value": "Open",
                "onclick": "OpenDoc()"
            }, {
                "value": "Close",
                "onclick": "CloseDoc()"
            }]
        }
    }
}

And in XML the same thing would have been:

<menu id="file" value="File">
  <popup>
    <menuitem value="New" onclick="CreateNewDoc()" />
    <menuitem value="Open" onclick="OpenDoc()" />
    <menuitem value="Close" onclick="CloseDoc()" />
  </popup>
</menu>

Ref.: json.org

Hope you now get an idea of what is JSON.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Patrick Desjardins
  • 136,852
  • 88
  • 292
  • 341
  • Anyway, I do not get the point to do a war about it, I'll find the exact reference of the other website I found it once I finish the rush I have to complete at work. brb later... I let you edit the post if you feel that it's needed. – Patrick Desjardins Nov 13 '08 at 14:54
4

From Wikipedia: JSON (Javascript object notation)

The JSON format is often used for transmitting structured data over a network connection in a process called serialization. Its main application is in Ajax web application programming, where it serves as an alternative to the use of the XML format.

Galwegian
  • 41,475
  • 16
  • 112
  • 158
3

The in-depth version seems to be well covered, maybe you're looking for the short-and-simplified version?

JSON is basically just a way to pass an array from one language to another.

It's used a lot for Ajax (amongst other things) because with Ajax you typically have a server-side language (PHP etc.) passing a set of results to a client-side language (javascript). Your javascript calls your PHP page with some parameters; your PHP page builds an array and echos it encodes it to JSON format; your javascript catches the JSON and decodes it back to an array to process.

There's more to it than that obviously (and for that reason I'm expecting a flurry of tear-streaked downvotes :) ), but that's all you need to get up and running with it.

JoeBloggs
  • 1,467
  • 9
  • 8
2

It is JavaScript Object Notation. You can use it to send data back and forward. It is often recommended since there is not so much overhead, like the one you get with XML. This is why it has become more popular than XML with Ajax.

Take a look at this: http://en.wikipedia.org/wiki/JSON

Mikael Söderström
  • 1,008
  • 8
  • 15
0

In my opinion when one wants to access webservice of different service provider such as Twitter,facebook etc over HTTP.

Then one must create a url and request for connection .When connection established a large amount of data comes from requesting site .

Example

<7b226665 65644974 656d7322 3a5b7b22 63617465 676f7279 223a7b22 6e616d65 223a2254 72616e73 706f7274 6174696f 6e222c22 68656164 65725f69 636f6e22 3a225c2f 686f6d65 5c2f6164 6d696e5c 2f707562 6c69635f 68746d6c 5c2f7072 6f647563 74696f6e 2e6d6973 73696f6e 7a65726f 2e6f7267>

This DATA is too much difficult to understand and arbitary in nature so we have 2 option for the representation of arbitrary data structures either in JSON format or XML format .But disadvantage in XML , it is syntactically more complex and bigger in file size than JSON. So it is better to use JSON

raaz
  • 12,410
  • 22
  • 64
  • 81
  • What should that example represent? It is neither JSON nor XML. So if you wanted it to be example data, then it's pretty much worthless unless you give examples with JSON and/or XML. And since the data seems to be entirely unstructured both formats aren't particularly well suited to representing it. – Joachim Sauer Oct 28 '09 at 11:30
  • I know this example doesn't in either in JSON or XML.But it is prior to that when requesting server sends the raw unstructured data.It is the responsibility of programmer Who wants to parse the unstructured data either in JSON or XML.And as previous posts already have given sample example of JSON and XML So I dont think to repeat it.. – raaz Oct 29 '09 at 06:01
0

JSON: JavaScript Object Notation.

JSON is a syntax for storing and exchanging data.

JSON is an easier-to-use alternative to XML.

JSON is a lightweight data-interchange format

JSON is language independent *

JSON is "self-describing" and easy to understand

EXAMPLE:

    {"employees":[

      {"firstName":"John", "lastName":"Doe"},

      {"firstName":"Anna", "lastName":"Smith"},

      {"firstName":"Peter", "lastName":"Jones"}

    ]}