Javascript Object Notation(JSON) is format used to exchange data between cross platforms . It known as an alternative to XML . JSON uses language independent text format at at the same time uses conventions that are familiar to C, C++, C#, Java, JavaScript, Perl, Python, and many others. JSON will encapsulate objects in a meaningful way so that it is easily understood by humans and can be parsed.
Advantage
  • Light weight
  • Ease of reading
  • Ease of parsing
  • language independent
  • Creating JSON data in Java

    JSON.org has supplied library files to create/parse JSON data with Java code. These libraries could be used in any Java/J2EE project and includes Servlet, Struts, JSF, JSP etc. JSONObject class is used to create and manipulate JSON data in Java . It is an unordered collection of name and value pairs. Its form is a string wrapped with curly braces and colons between the names and values, commas between the values and names. Internally the object has get() and opt() methods for accessing the values by its corresponding name. The values can be any of following types Boolean, JSONArray, JSONObject, Number,String or JSONObject.NULL .

    JSON in JavaScript
    JSON uses the object literal notation of JavaScript. So JSON is considered to be a subset of JavaScript, as a result it can be used in the language effectively JSON formatting functions are widely available across popular javascript implementations
    As JSON is just a string of text , it needs to be converted to an object before using it. It can be done in JavaScript using eval() function,even though it is safer to use a JSON parser.
    Including JSON parser file on a web page allows you to to use following parsing functions.
  • JSON.parse(strJSON) – this converts a JSON string into JavaScript object.
  • JSON.stringify(objJSON) -this converts a JavaScript object into JSON string.
  • function SendRequest(MSG)
    {
    var objJSON = {
    “msg” : MSG
    };
    var strJSON = encodeURIComponent(JSON.stringify(objJSON));
    new Ajax.Request(“ReceiveJSON.jsp”,
    function SendRequest(MSG)
    {
    method: “post”,
    parameters: “strJSON=” + strJSON,
    onComplete: Respond
    });
    }
    in server it can be retrieved by
    JSONObject json = (JSONObject) JSONSerializer.toJSON( jsonTxt );
    String msg = json.getString(“msg”);
    JSON provides a succinct encoding for application data structures and is typically used in scenarios where a JavaScript implementation is required exchanging data among applications, e.g in Ajax web applications. The importance of JSON lies in its simplicity to understand, adopt, and implement. JSON seems simple to learn for developers who already familiar with JavaScript or other similar programming languages .