SlideShare una empresa de Scribd logo
1 de 19
Salesforce JSON support
Winter 12

By – Jitendra Zaa

0
Agenda
•
•
•
•
•
•
•

What is JSON
Advantage of JSON over XML
Other reasons to use JSON
JSON Syntax / Guidelines
Deserialize and Serialize in Single line - Winter 12
Visualforce Page Output as JSON
Google Map API - Demo

1
What is JSON
•
•
•
•
•

JSON Stands for “JavaScript Object Notation”.
Language Independent representation of objects.
Parsers widely available in many languages.
Alternative to XML.
JSON can be transmitted over http / https.

2
XML Example
<Person>
<FirstName>Foo</FirstName>
<LastName>Bar</LastName>
</person>

3
JSON Example
{
“FirstName” : “Foo”,
“LastName” : “Bar”
}

4
JSON Advantage over XML
• XML is Verbose.
• More size than of equivalent JSON representation
because of repeated Tags.
• JSON Simple to represent

5
Why JSON
• REST is very common and supports JSON widely.
• REST and JSON are the music of the internet.
• Google , Yahoo, D&B web services exposed as REST
with response type JSON.

6
JSON Guidelines
Key – Value enclosed in double quotes (String).
Value - can again anything of datatype.
{} – represents Object
[] – represents Array
, - Separates data element within Object
Supports basically four data type:
1. Boolean
2. Number
3. String
4. Object
7
Nested Object JSON
{
“FirstName” : “Foo”,
“LastName” : “Bar”,
“Address” :
{
“city” : “Pune”,
“state” : “Maharashtra”,
“country” : “India”
}

}
8
How to Work with JSON – Before
Winter 12
• AppExchange and other codes were available for
Parsing JSON.
• Performance Overhead.
• Learning curve more.

9
Deserialize JSON – Winter 12 API
JSON String :
{
“FirstName” : “Foo”,
“LastName” : “Bar”
}

Equivalent Apex Class:
Class Person
{
public String FirstName;
public String LastName;
}

10
Deserialize JSON – Single Line
Person d = (Person )System.JSON.deserialize(jsonString, Person.class);

JSON Format String

Determine the output
object type of the JSON

11
Serialize Apex Class to JSON
JSON.serialize(object);

Object to convert to
JSON

12
JSON MIME Type
• application/json

13
Visualforce Page Output as JSON
•
•
•
•

contentType="application/x-JavaScript; charset=utf-8"
showHeader="false"
standardStylesheets="false"
sidebar="false"

14
Demo
Get distance between two points using Google API
http://maps.googleapis.com/maps/api/distancematrix/json?origi
ns=Nagpur+Maharashtra+india&destinations=Pune+Maharasht
ra+india&sensor=false

15
Response from Google
{

}

destination_addresses:[
"Pune, Maharashtra, India"
],
origin_addresses:[
"Nagpur, Maharashtra, India"
],
rows:[
{
elements:[
{
distance:{
text:"730 km",
value:730315
},
duration:{
text:"11 hours 25 mins",
value:41126
},
status:"OK"
}
]
}
],
status:"OK"

16
Apex Class Equivalent to JSON
response
Class GoogleResponse
{
public String[] destination_addresses;
public String[] origin_addresses;
public Row[] rows;
public String status;
}
Class Row
{
public Elements[] elements;
}
Class Elements
{
public
public
public
}
Class Values
{
public
public
}
17

Values distance;
Values duration;
String status;

String text;
String value;
Deserialize JSON
String json = '{ "destination_addresses":[ "Pune, Maharashtra, India" ],
"origin_addresses":[ "Nagpur, Maharashtra, India" ],"rows":[
{
"elements":[
{
"distance":{
"text":"730 km",
"value":730315
},
"duration":{
"text":"11 hours
25 mins",
"value":41126
},
"status":"OK"
}
]
} ], "status":"OK"}';
GoogleResponse d = (GoogleResponse)System.JSON.deserialize(json,
GoogleResponse.class);

18

Más contenido relacionado

La actualidad más candente (11)

Google Protocol Buffers
Google Protocol BuffersGoogle Protocol Buffers
Google Protocol Buffers
 
Php
PhpPhp
Php
 
PgREST: Node.js in the Database
PgREST: Node.js in the DatabasePgREST: Node.js in the Database
PgREST: Node.js in the Database
 
Avro - More Than Just a Serialization Framework - CHUG - 20120416
Avro - More Than Just a Serialization Framework - CHUG - 20120416Avro - More Than Just a Serialization Framework - CHUG - 20120416
Avro - More Than Just a Serialization Framework - CHUG - 20120416
 
Week 8 intro to python
Week 8   intro to pythonWeek 8   intro to python
Week 8 intro to python
 
Introduction to Thrift
Introduction to ThriftIntroduction to Thrift
Introduction to Thrift
 
BRAINREPUBLIC - Powered by no-SQL
BRAINREPUBLIC - Powered by no-SQLBRAINREPUBLIC - Powered by no-SQL
BRAINREPUBLIC - Powered by no-SQL
 
Xcap tutorial
Xcap tutorialXcap tutorial
Xcap tutorial
 
php basic part one
php basic part onephp basic part one
php basic part one
 
Reversing Google Protobuf protocol
Reversing Google Protobuf protocolReversing Google Protobuf protocol
Reversing Google Protobuf protocol
 
slidesharenew1
slidesharenew1slidesharenew1
slidesharenew1
 

Similar a JSON Support in Salesforce - winter 12

Devoxx - JSON Validation using JSON Schema and Jackson
Devoxx - JSON Validation using JSON Schema and JacksonDevoxx - JSON Validation using JSON Schema and Jackson
Devoxx - JSON Validation using JSON Schema and Jackson
srondal
 
Java Script Based Client Server Webapps 2
Java Script Based Client Server Webapps 2Java Script Based Client Server Webapps 2
Java Script Based Client Server Webapps 2
kriszyp
 
JSON Fuzzing: New approach to old problems
JSON Fuzzing: New  approach to old problemsJSON Fuzzing: New  approach to old problems
JSON Fuzzing: New approach to old problems
titanlambda
 

Similar a JSON Support in Salesforce - winter 12 (20)

Json at work overview and ecosystem-v2.0
Json at work   overview and ecosystem-v2.0Json at work   overview and ecosystem-v2.0
Json at work overview and ecosystem-v2.0
 
Json
JsonJson
Json
 
Hands on JSON
Hands on JSONHands on JSON
Hands on JSON
 
Devoxx - JSON Validation using JSON Schema and Jackson
Devoxx - JSON Validation using JSON Schema and JacksonDevoxx - JSON Validation using JSON Schema and Jackson
Devoxx - JSON Validation using JSON Schema and Jackson
 
Comparing JSON Libraries - July 19 2011
Comparing JSON Libraries - July 19 2011Comparing JSON Libraries - July 19 2011
Comparing JSON Libraries - July 19 2011
 
Json
JsonJson
Json
 
Graph Analysis over JSON, Larus
Graph Analysis over JSON, LarusGraph Analysis over JSON, Larus
Graph Analysis over JSON, Larus
 
Advanced Json
Advanced JsonAdvanced Json
Advanced Json
 
Java Script Based Client Server Webapps 2
Java Script Based Client Server Webapps 2Java Script Based Client Server Webapps 2
Java Script Based Client Server Webapps 2
 
Json
JsonJson
Json
 
Json tutorial, a beguiner guide
Json tutorial, a beguiner guideJson tutorial, a beguiner guide
Json tutorial, a beguiner guide
 
No sql way_in_pg
No sql way_in_pgNo sql way_in_pg
No sql way_in_pg
 
The NoSQL Way in Postgres
The NoSQL Way in PostgresThe NoSQL Way in Postgres
The NoSQL Way in Postgres
 
Json
JsonJson
Json
 
Json
JsonJson
Json
 
java script json
java script jsonjava script json
java script json
 
What is JSON-FP
What is JSON-FPWhat is JSON-FP
What is JSON-FP
 
JSON
JSONJSON
JSON
 
JSON Fuzzing: New approach to old problems
JSON Fuzzing: New  approach to old problemsJSON Fuzzing: New  approach to old problems
JSON Fuzzing: New approach to old problems
 
Writing Domain Specific Languages with JSON Schema
Writing Domain Specific Languages with JSON SchemaWriting Domain Specific Languages with JSON Schema
Writing Domain Specific Languages with JSON Schema
 

Más de Jitendra Zaa

Más de Jitendra Zaa (20)

Episode 13 - Advanced Apex Triggers
Episode 13 - Advanced Apex TriggersEpisode 13 - Advanced Apex Triggers
Episode 13 - Advanced Apex Triggers
 
Episode 18 - Asynchronous Apex
Episode 18 - Asynchronous ApexEpisode 18 - Asynchronous Apex
Episode 18 - Asynchronous Apex
 
Episode 15 - Basics of Javascript
Episode 15 - Basics of JavascriptEpisode 15 - Basics of Javascript
Episode 15 - Basics of Javascript
 
Episode 23 - Design Pattern 3
Episode 23 - Design Pattern 3Episode 23 - Design Pattern 3
Episode 23 - Design Pattern 3
 
Episode 24 - Live Q&A for getting started with Salesforce
Episode 24 - Live Q&A for getting started with SalesforceEpisode 24 - Live Q&A for getting started with Salesforce
Episode 24 - Live Q&A for getting started with Salesforce
 
Episode 22 - Design Pattern 2
Episode 22 - Design Pattern 2Episode 22 - Design Pattern 2
Episode 22 - Design Pattern 2
 
Episode 21 - Design Pattern 1
Episode 21 - Design Pattern 1Episode 21 - Design Pattern 1
Episode 21 - Design Pattern 1
 
Episode 20 - Trigger Frameworks in Salesforce
Episode 20 - Trigger Frameworks in SalesforceEpisode 20 - Trigger Frameworks in Salesforce
Episode 20 - Trigger Frameworks in Salesforce
 
Episode 19 - Asynchronous Apex - Batch apex & schedulers
Episode 19 - Asynchronous Apex - Batch apex & schedulersEpisode 19 - Asynchronous Apex - Batch apex & schedulers
Episode 19 - Asynchronous Apex - Batch apex & schedulers
 
Episode 17 - Handling Events in Lightning Web Component
Episode 17 - Handling Events in Lightning Web ComponentEpisode 17 - Handling Events in Lightning Web Component
Episode 17 - Handling Events in Lightning Web Component
 
Episode 16 - Introduction to LWC
Episode 16 - Introduction to LWCEpisode 16 - Introduction to LWC
Episode 16 - Introduction to LWC
 
Introduction to mulesoft - Alpharetta Developer Group Meet
Introduction to mulesoft - Alpharetta Developer Group MeetIntroduction to mulesoft - Alpharetta Developer Group Meet
Introduction to mulesoft - Alpharetta Developer Group Meet
 
Episode 12 - Basics of Trigger
Episode 12 - Basics of TriggerEpisode 12 - Basics of Trigger
Episode 12 - Basics of Trigger
 
Episode 11 building & exposing rest api in salesforce v1.0
Episode 11   building & exposing rest api in salesforce v1.0Episode 11   building & exposing rest api in salesforce v1.0
Episode 11 building & exposing rest api in salesforce v1.0
 
Episode 10 - External Services in Salesforce
Episode 10 - External Services in SalesforceEpisode 10 - External Services in Salesforce
Episode 10 - External Services in Salesforce
 
Episode 14 - Basics of HTML for Salesforce
Episode 14 - Basics of HTML for SalesforceEpisode 14 - Basics of HTML for Salesforce
Episode 14 - Basics of HTML for Salesforce
 
South East Dreamin 2019
South East Dreamin 2019South East Dreamin 2019
South East Dreamin 2019
 
Episode 9 - Building soap integrations in salesforce
Episode 9 - Building soap integrations  in salesforceEpisode 9 - Building soap integrations  in salesforce
Episode 9 - Building soap integrations in salesforce
 
Episode 6 - DML, Transaction and Error handling in Salesforce
Episode 6 - DML, Transaction and Error handling in SalesforceEpisode 6 - DML, Transaction and Error handling in Salesforce
Episode 6 - DML, Transaction and Error handling in Salesforce
 
Episode 5 - Writing unit tests in Salesforce
Episode 5 - Writing unit tests in SalesforceEpisode 5 - Writing unit tests in Salesforce
Episode 5 - Writing unit tests in Salesforce
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Último (20)

Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
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...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
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
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
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, ...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 

JSON Support in Salesforce - winter 12

  • 1. Salesforce JSON support Winter 12 By – Jitendra Zaa 0
  • 2. Agenda • • • • • • • What is JSON Advantage of JSON over XML Other reasons to use JSON JSON Syntax / Guidelines Deserialize and Serialize in Single line - Winter 12 Visualforce Page Output as JSON Google Map API - Demo 1
  • 3. What is JSON • • • • • JSON Stands for “JavaScript Object Notation”. Language Independent representation of objects. Parsers widely available in many languages. Alternative to XML. JSON can be transmitted over http / https. 2
  • 5. JSON Example { “FirstName” : “Foo”, “LastName” : “Bar” } 4
  • 6. JSON Advantage over XML • XML is Verbose. • More size than of equivalent JSON representation because of repeated Tags. • JSON Simple to represent 5
  • 7. Why JSON • REST is very common and supports JSON widely. • REST and JSON are the music of the internet. • Google , Yahoo, D&B web services exposed as REST with response type JSON. 6
  • 8. JSON Guidelines Key – Value enclosed in double quotes (String). Value - can again anything of datatype. {} – represents Object [] – represents Array , - Separates data element within Object Supports basically four data type: 1. Boolean 2. Number 3. String 4. Object 7
  • 9. Nested Object JSON { “FirstName” : “Foo”, “LastName” : “Bar”, “Address” : { “city” : “Pune”, “state” : “Maharashtra”, “country” : “India” } } 8
  • 10. How to Work with JSON – Before Winter 12 • AppExchange and other codes were available for Parsing JSON. • Performance Overhead. • Learning curve more. 9
  • 11. Deserialize JSON – Winter 12 API JSON String : { “FirstName” : “Foo”, “LastName” : “Bar” } Equivalent Apex Class: Class Person { public String FirstName; public String LastName; } 10
  • 12. Deserialize JSON – Single Line Person d = (Person )System.JSON.deserialize(jsonString, Person.class); JSON Format String Determine the output object type of the JSON 11
  • 13. Serialize Apex Class to JSON JSON.serialize(object); Object to convert to JSON 12
  • 14. JSON MIME Type • application/json 13
  • 15. Visualforce Page Output as JSON • • • • contentType="application/x-JavaScript; charset=utf-8" showHeader="false" standardStylesheets="false" sidebar="false" 14
  • 16. Demo Get distance between two points using Google API http://maps.googleapis.com/maps/api/distancematrix/json?origi ns=Nagpur+Maharashtra+india&destinations=Pune+Maharasht ra+india&sensor=false 15
  • 17. Response from Google { } destination_addresses:[ "Pune, Maharashtra, India" ], origin_addresses:[ "Nagpur, Maharashtra, India" ], rows:[ { elements:[ { distance:{ text:"730 km", value:730315 }, duration:{ text:"11 hours 25 mins", value:41126 }, status:"OK" } ] } ], status:"OK" 16
  • 18. Apex Class Equivalent to JSON response Class GoogleResponse { public String[] destination_addresses; public String[] origin_addresses; public Row[] rows; public String status; } Class Row { public Elements[] elements; } Class Elements { public public public } Class Values { public public } 17 Values distance; Values duration; String status; String text; String value;
  • 19. Deserialize JSON String json = '{ "destination_addresses":[ "Pune, Maharashtra, India" ], "origin_addresses":[ "Nagpur, Maharashtra, India" ],"rows":[ { "elements":[ { "distance":{ "text":"730 km", "value":730315 }, "duration":{ "text":"11 hours 25 mins", "value":41126 }, "status":"OK" } ] } ], "status":"OK"}'; GoogleResponse d = (GoogleResponse)System.JSON.deserialize(json, GoogleResponse.class); 18