SlideShare uma empresa Scribd logo
1 de 6
JSON


      JSON stands for JavaScript Object Notation that is a language
independent text format which is fast and easy to understand. That means it
is really very simple and easy to learn without sparing much time. In
another words we can say that JavaScript Object Notation is a lightweight
data-interchange format that is completely language independent but with
some conventions.

Why JSON?

    1. Because JSON is easy to write. It is just like creating and accessing
       class in javascript in object notation
    2. If you like Hash Tables, you will fall in love with JSON.
    3. JSON is just key: value pairs assigned within an object.
    4. JSON is very fast.
    5. It is easy to understand and can be integrated in any web application
       very easily.101194
    6. Better organized data if prepared in well mannered way.

Creating Objects in JavaScript using JSON:

JSON is syntax for passing around objects that contain name/value pairs,
arrays and other objects.

We can create objects in JSON with JavaScript in many ways:

       "var JSONObjectName ={};" will create an empty object.
       "var JSONObjectName= new Object();" will create a new Object.
       "var JSONObjectName = { "name ":"amit", "age":23}; will
       create an Object with attribute name which contains value in String
       and age with numeric value.

  Now by creating this object we can access attributes by only "." operator.

Squiggles, Squares, Colons and Commas

  1.   Squiggly brackets act as 'containers'
  2.   Square brackets holds arrays
  3.   Names and values are separated by a colon.
  4.   Array elements are separated by commas
Advantages of JSON:

      Because JSON was designed for the purpose of serializing and
unserializing data being sent to and from JavaScript applications, the
advantages of using JSON relate to the advantages of JSON over other
means of serialization. The most well-known means of serializing data for
transmission to and from applications at present is XML. Yet, XML is a
rather cumbersome means of serialization.

      First, the sender must encode the data to be serialized based on a
document type definition that the recipient understands. Doing so creates a
great deal of extra padding around the actual data no matter which DTD is
used. So, the size of XML documents is often fairly large in comparison with
the actual set of values they contain.

       Second, the recipient must receive the stream of XML and decode the
data in order to then put that data into memory. In comparison, the
serialization of data using JSON by the sender is relatively quick and
compact because the structure of JSON reflects the structure of standard
programming data types and the encoding mechanism adds only the
minimum number of characters required to indicate the structure and value
of the data.

      Once the recipient receives the JSON serialized data, then, the only
processing needing to be done is to evaluate the text of the string using
either JavaScript's built-in eval function or a compatible function in another
language. The other standard comparison is YAML, which is able to serialize
complex data sets without relying upon a DTD and needs a simpler parser to
both read and write than XML. However, even the simplified YAML parsers
generally require more time and generate larger serialized data streams
than JSON.


JSON is like XML because:

   1. They are both 'self-describing' meaning that values are named, and
      thus 'human readable'
   2. Both are hierarchical. (i.e. you can have values within values.)
   3. Both can be parsed and used by lots of programming languages
   4. Both can be passed around using AJAX (i.e. httpWebRequest)
JSON is Unlike XML because:

  1. XML uses angle brackets, with a tag name at the start and end of an
     element: JSON uses squiggly brackets with the name only at the
     beginning of the element.
  2. JSON is less verbose so it's definitely quicker for humans to write, and
     probably quicker for us to read.
  3. JSON can be parsed trivially using the eval() procedure in JavaScript
  4. JSON includes arrays {where each element doesn't have a name of its
     own}
  5. In XML you can use any name you want for an element, in JSON you
     can't use reserved words from javascript



Example: Object creation in JSON in JavaScript

      <html>
      <head>
      <title>
       Object creation in JSON in JavaScript
      </title>
      <script language="javascript" >
      var JSONObject = { "name"       : "Amit",
                     "address" : "B-123 Bangalow",
                     "age"    : 23,
                    "phone"    : "011-4565763",
                    "MobileNo" : 0981100092
             };
      document.write("<h2><font color='blue'>Name</font>::"
          +JSONObject.name+"</h2>");
      document.write("<h2><font color='blue'>Address</font>::"
          +JSONObject.address+"</h2>");
      document.write("<h2><font color='blue'>Age</font>::"
          +JSONObject.age+"</h2>");
      document.write("<h2><font color='blue'>Phone No.</font>::"
          +JSONObject.phone+"</h2>");
      document.write("<h2><font color='blue'>Mobile No.</font>::"
          +JSONObject.MobileNo+"</h2>");
      </script>
      </head>
<body>
       <h3>Example of object creation in JSON in JavaScript</h3>
       </body>
       </html>

 How to use JSON in JQUERY:

     You have a JSON file with some information stored in it. You want to
import that information from the JSON file into the current web page
asynchronously. The JSON file is a file that contains information regarding
‘name’ and ‘value’ pairs.

The HTML file should look like this:
<body>
<p>For information from JSON file click the button given below :<br>
<input type="submit" id="submit"/>
<div id="message"></div>
</body>

The JSON file drinkinfo.json have information like this:

[
{"optiontext" : "Tea", "optionvalue" : "Tea"},
{"optiontext" : "Coffee", "optionvalue" : "Coffee"},
{"optiontext" : "Juice", "optionvalue" : "Juice"}
]

This JSON file can be used in the JQUERY like this:

$(document).ready (function () {
$('#submit').click (function () {
$.ajax ({
type:"GET",
url:"drinkinfo.json",
dataType:"json",
success: function (data) {
var drinks="<ul>";
$.each(data, function(i,n){
drinks+="<li>"+n["optiontext"]+"</li>";
});
drinks+="</ul>";
$('#message').append(drinks);
}
});
return false;
});
});

      The information received in data contains two attributes: optiontext
and optionvalue, and we want to return only the contents of the optiontext
attribute to the web page, in the form of a list. We therefore make use of
the each() method to parse each object stored in data. In the callback
function of each() method, we use two parameters: i and n where i refers to
the index location of the object in data and n refers to object containing
information (in terms of attributes optiontext and optionvalue).

      We can also simplify the above jQuery code by making use of the
$.getJSON() method, which is particularly designed for retrieving data from
a JSON file. This method makes a GET request to the specified url address
(on the server), along with its passed parameters, and returns information in
the form of JSON encoded data. Its syntax looks like this:
      $.getJSON (url, parameters, callbackfuncton)

And the parameters are:
      url is name of the file along with its address on the server
      parameters is a string containing information in the form of name and
      value pairs to be passed to the url
      callback function is the response generated from the server , when the
      request succeeds

      The jQuery code to use the $.getJSON() method is as shown here, and
it works much the same way as our previous solution but as you can see,
leads to some neater code:

$(document).ready (function () {
$('#submit').click (function () {
$.getJSON ('drinkinfo.json', function (data){
var drinks="<ul>";
$.each (data, function (i,n){
drinks +="<li>"+n ["optiontext"]+"</li>";
});
drinks +="</ul>";
$('#message').append (drinks);
});
return false;
});
});
Limitations of JSON:

      The most important disadvantage of JSON is that the format is very
hard to read for humans, and that, of course, every single comma, quote,
and bracket should be in exactly the correct place. While this is also true of
XML, JSON's welter of complicated-looking syntax, like the}}]} at the end of
the data snippet, may frighten the newbies and make for complicated
debugging.

      JSON shows its greatest weakness. Yes the little semantics JSON data
structures have makes them easy to work with. One knows how to interpret
an array, how to interpret a number and how to interpret a Boolean. But this
is very minimal semantics. It is very much pre web semantics. It works as
long as the client and the server, the publisher of the data and the consumer
of the data are closely tied together. Why so? Because there is no use of
URIs, Universal Names, in JSON. JSON has a provincial semantics. Compare
to XML which gives a place for the concept of a namespace specified in
terms of a URI.

Mais conteúdo relacionado

Mais procurados (20)

Working with JSON
Working with JSONWorking with JSON
Working with JSON
 
Java Strings
Java StringsJava Strings
Java Strings
 
Java interface
Java interfaceJava interface
Java interface
 
Interface in java
Interface in javaInterface in java
Interface in java
 
Intro to JSON
Intro to JSONIntro to JSON
Intro to JSON
 
Url Connection
Url ConnectionUrl Connection
Url Connection
 
PHP - Introduction to File Handling with PHP
PHP -  Introduction to  File Handling with PHPPHP -  Introduction to  File Handling with PHP
PHP - Introduction to File Handling with PHP
 
enums
enumsenums
enums
 
Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)Basic Concepts of OOPs (Object Oriented Programming in Java)
Basic Concepts of OOPs (Object Oriented Programming in Java)
 
Javascript essentials
Javascript essentialsJavascript essentials
Javascript essentials
 
Angularjs PPT
Angularjs PPTAngularjs PPT
Angularjs PPT
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
Introduction to class in java
Introduction to class in javaIntroduction to class in java
Introduction to class in java
 
Express js
Express jsExpress js
Express js
 
Basic concept of OOP's
Basic concept of OOP'sBasic concept of OOP's
Basic concept of OOP's
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
 
Ppt on this and super keyword
Ppt on this and super keywordPpt on this and super keyword
Ppt on this and super keyword
 
JSON and XML
JSON and XMLJSON and XML
JSON and XML
 
What is Python JSON | Edureka
What is Python JSON | EdurekaWhat is Python JSON | Edureka
What is Python JSON | Edureka
 
MYSQL - PHP Database Connectivity
MYSQL - PHP Database ConnectivityMYSQL - PHP Database Connectivity
MYSQL - PHP Database Connectivity
 

Destaque (12)

JSON
JSONJSON
JSON
 
Json
JsonJson
Json
 
Json
JsonJson
Json
 
Dhtml
DhtmlDhtml
Dhtml
 
Introduction to XHTML
Introduction to XHTMLIntroduction to XHTML
Introduction to XHTML
 
Dynamic HTML
Dynamic HTMLDynamic HTML
Dynamic HTML
 
Dhtml
DhtmlDhtml
Dhtml
 
XHTML
XHTMLXHTML
XHTML
 
Xhtml
XhtmlXhtml
Xhtml
 
Dynamic HTML (DHTML)
Dynamic HTML (DHTML)Dynamic HTML (DHTML)
Dynamic HTML (DHTML)
 
Js ppt
Js pptJs ppt
Js ppt
 
Java script ppt
Java script pptJava script ppt
Java script ppt
 

Semelhante a Json (20)

JSON & AJAX.pptx
JSON & AJAX.pptxJSON & AJAX.pptx
JSON & AJAX.pptx
 
Basics of JSON (JavaScript Object Notation) with examples
Basics of JSON (JavaScript Object Notation) with examplesBasics of JSON (JavaScript Object Notation) with examples
Basics of JSON (JavaScript Object Notation) with examples
 
JSON-(JavaScript Object Notation)
JSON-(JavaScript Object Notation)JSON-(JavaScript Object Notation)
JSON-(JavaScript Object Notation)
 
Json
JsonJson
Json
 
module 2.pptx for full stack mobile development application on backend applic...
module 2.pptx for full stack mobile development application on backend applic...module 2.pptx for full stack mobile development application on backend applic...
module 2.pptx for full stack mobile development application on backend applic...
 
Intro to JSON
Intro to JSONIntro to JSON
Intro to JSON
 
Json tutorial, a beguiner guide
Json tutorial, a beguiner guideJson tutorial, a beguiner guide
Json tutorial, a beguiner guide
 
J s-o-n-120219575328402-3
J s-o-n-120219575328402-3J s-o-n-120219575328402-3
J s-o-n-120219575328402-3
 
Json
JsonJson
Json
 
JavaScript Lessons 2023 V2
JavaScript Lessons 2023 V2JavaScript Lessons 2023 V2
JavaScript Lessons 2023 V2
 
Json – java script object notation
Json – java script object notationJson – java script object notation
Json – java script object notation
 
Json – java script object notation
Json – java script object notationJson – java script object notation
Json – java script object notation
 
Json
Json Json
Json
 
Hands on JSON
Hands on JSONHands on JSON
Hands on JSON
 
JSON Injection
JSON InjectionJSON Injection
JSON Injection
 
Json
JsonJson
Json
 
Json
JsonJson
Json
 
java script json
java script jsonjava script json
java script json
 
All about XML, JSON and related topics..
All about XML, JSON and related topics..All about XML, JSON and related topics..
All about XML, JSON and related topics..
 
Json
JsonJson
Json
 

Mais de Anand Kumar Rajana (13)

Interface Vs Abstact
Interface Vs AbstactInterface Vs Abstact
Interface Vs Abstact
 
Anand's Leadership Assessment
Anand's Leadership AssessmentAnand's Leadership Assessment
Anand's Leadership Assessment
 
Understanding linq
Understanding linqUnderstanding linq
Understanding linq
 
Rhino Mocks
Rhino MocksRhino Mocks
Rhino Mocks
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
The Seven Pillars Of Asp.Net
The Seven Pillars Of Asp.NetThe Seven Pillars Of Asp.Net
The Seven Pillars Of Asp.Net
 
What Do You Mean By NUnit
What Do You Mean By NUnitWhat Do You Mean By NUnit
What Do You Mean By NUnit
 
Wcf
WcfWcf
Wcf
 
Sql Server 2012 Installation..
Sql Server 2012 Installation..Sql Server 2012 Installation..
Sql Server 2012 Installation..
 
Jquery Ajax
Jquery AjaxJquery Ajax
Jquery Ajax
 
Dependency Injection
Dependency InjectionDependency Injection
Dependency Injection
 
jQuery Ajax
jQuery AjaxjQuery Ajax
jQuery Ajax
 
J Query Introduction And JQuery Selectors
J Query Introduction And JQuery SelectorsJ Query Introduction And JQuery Selectors
J Query Introduction And JQuery Selectors
 

Último

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 

Último (20)

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 

Json

  • 1. JSON JSON stands for JavaScript Object Notation that is a language independent text format which is fast and easy to understand. That means it is really very simple and easy to learn without sparing much time. In another words we can say that JavaScript Object Notation is a lightweight data-interchange format that is completely language independent but with some conventions. Why JSON? 1. Because JSON is easy to write. It is just like creating and accessing class in javascript in object notation 2. If you like Hash Tables, you will fall in love with JSON. 3. JSON is just key: value pairs assigned within an object. 4. JSON is very fast. 5. It is easy to understand and can be integrated in any web application very easily.101194 6. Better organized data if prepared in well mannered way. Creating Objects in JavaScript using JSON: JSON is syntax for passing around objects that contain name/value pairs, arrays and other objects. We can create objects in JSON with JavaScript in many ways: "var JSONObjectName ={};" will create an empty object. "var JSONObjectName= new Object();" will create a new Object. "var JSONObjectName = { "name ":"amit", "age":23}; will create an Object with attribute name which contains value in String and age with numeric value. Now by creating this object we can access attributes by only "." operator. Squiggles, Squares, Colons and Commas 1. Squiggly brackets act as 'containers' 2. Square brackets holds arrays 3. Names and values are separated by a colon. 4. Array elements are separated by commas
  • 2. Advantages of JSON: Because JSON was designed for the purpose of serializing and unserializing data being sent to and from JavaScript applications, the advantages of using JSON relate to the advantages of JSON over other means of serialization. The most well-known means of serializing data for transmission to and from applications at present is XML. Yet, XML is a rather cumbersome means of serialization. First, the sender must encode the data to be serialized based on a document type definition that the recipient understands. Doing so creates a great deal of extra padding around the actual data no matter which DTD is used. So, the size of XML documents is often fairly large in comparison with the actual set of values they contain. Second, the recipient must receive the stream of XML and decode the data in order to then put that data into memory. In comparison, the serialization of data using JSON by the sender is relatively quick and compact because the structure of JSON reflects the structure of standard programming data types and the encoding mechanism adds only the minimum number of characters required to indicate the structure and value of the data. Once the recipient receives the JSON serialized data, then, the only processing needing to be done is to evaluate the text of the string using either JavaScript's built-in eval function or a compatible function in another language. The other standard comparison is YAML, which is able to serialize complex data sets without relying upon a DTD and needs a simpler parser to both read and write than XML. However, even the simplified YAML parsers generally require more time and generate larger serialized data streams than JSON. JSON is like XML because: 1. They are both 'self-describing' meaning that values are named, and thus 'human readable' 2. Both are hierarchical. (i.e. you can have values within values.) 3. Both can be parsed and used by lots of programming languages 4. Both can be passed around using AJAX (i.e. httpWebRequest)
  • 3. JSON is Unlike XML because: 1. XML uses angle brackets, with a tag name at the start and end of an element: JSON uses squiggly brackets with the name only at the beginning of the element. 2. JSON is less verbose so it's definitely quicker for humans to write, and probably quicker for us to read. 3. JSON can be parsed trivially using the eval() procedure in JavaScript 4. JSON includes arrays {where each element doesn't have a name of its own} 5. In XML you can use any name you want for an element, in JSON you can't use reserved words from javascript Example: Object creation in JSON in JavaScript <html> <head> <title> Object creation in JSON in JavaScript </title> <script language="javascript" > var JSONObject = { "name" : "Amit", "address" : "B-123 Bangalow", "age" : 23, "phone" : "011-4565763", "MobileNo" : 0981100092 }; document.write("<h2><font color='blue'>Name</font>::" +JSONObject.name+"</h2>"); document.write("<h2><font color='blue'>Address</font>::" +JSONObject.address+"</h2>"); document.write("<h2><font color='blue'>Age</font>::" +JSONObject.age+"</h2>"); document.write("<h2><font color='blue'>Phone No.</font>::" +JSONObject.phone+"</h2>"); document.write("<h2><font color='blue'>Mobile No.</font>::" +JSONObject.MobileNo+"</h2>"); </script> </head>
  • 4. <body> <h3>Example of object creation in JSON in JavaScript</h3> </body> </html> How to use JSON in JQUERY: You have a JSON file with some information stored in it. You want to import that information from the JSON file into the current web page asynchronously. The JSON file is a file that contains information regarding ‘name’ and ‘value’ pairs. The HTML file should look like this: <body> <p>For information from JSON file click the button given below :<br> <input type="submit" id="submit"/> <div id="message"></div> </body> The JSON file drinkinfo.json have information like this: [ {"optiontext" : "Tea", "optionvalue" : "Tea"}, {"optiontext" : "Coffee", "optionvalue" : "Coffee"}, {"optiontext" : "Juice", "optionvalue" : "Juice"} ] This JSON file can be used in the JQUERY like this: $(document).ready (function () { $('#submit').click (function () { $.ajax ({ type:"GET", url:"drinkinfo.json", dataType:"json", success: function (data) { var drinks="<ul>"; $.each(data, function(i,n){ drinks+="<li>"+n["optiontext"]+"</li>"; }); drinks+="</ul>"; $('#message').append(drinks); } });
  • 5. return false; }); }); The information received in data contains two attributes: optiontext and optionvalue, and we want to return only the contents of the optiontext attribute to the web page, in the form of a list. We therefore make use of the each() method to parse each object stored in data. In the callback function of each() method, we use two parameters: i and n where i refers to the index location of the object in data and n refers to object containing information (in terms of attributes optiontext and optionvalue). We can also simplify the above jQuery code by making use of the $.getJSON() method, which is particularly designed for retrieving data from a JSON file. This method makes a GET request to the specified url address (on the server), along with its passed parameters, and returns information in the form of JSON encoded data. Its syntax looks like this: $.getJSON (url, parameters, callbackfuncton) And the parameters are: url is name of the file along with its address on the server parameters is a string containing information in the form of name and value pairs to be passed to the url callback function is the response generated from the server , when the request succeeds The jQuery code to use the $.getJSON() method is as shown here, and it works much the same way as our previous solution but as you can see, leads to some neater code: $(document).ready (function () { $('#submit').click (function () { $.getJSON ('drinkinfo.json', function (data){ var drinks="<ul>"; $.each (data, function (i,n){ drinks +="<li>"+n ["optiontext"]+"</li>"; }); drinks +="</ul>"; $('#message').append (drinks); }); return false; }); });
  • 6. Limitations of JSON: The most important disadvantage of JSON is that the format is very hard to read for humans, and that, of course, every single comma, quote, and bracket should be in exactly the correct place. While this is also true of XML, JSON's welter of complicated-looking syntax, like the}}]} at the end of the data snippet, may frighten the newbies and make for complicated debugging. JSON shows its greatest weakness. Yes the little semantics JSON data structures have makes them easy to work with. One knows how to interpret an array, how to interpret a number and how to interpret a Boolean. But this is very minimal semantics. It is very much pre web semantics. It works as long as the client and the server, the publisher of the data and the consumer of the data are closely tied together. Why so? Because there is no use of URIs, Universal Names, in JSON. JSON has a provincial semantics. Compare to XML which gives a place for the concept of a namespace specified in terms of a URI.