SlideShare una empresa de Scribd logo
1 de 67
Descargar para leer sin conexión
JSON at Work -
Overview and Ecosystem
        Tom Marrs
         Architect
Your Profile
Really?



      What else?



             How?
What’s The Point?

JSON -
  much
         more ...
JSON Ecosystem

               JSON Core

Schema                              Search



                              Dev Tools
    APIs

                       REST
           Transform
Our Agenda
We’re Not Covering
        :(-
REST


XML


SOA
JSON Beginnings

www.json.org

2001 - Douglas Crockford

2006 - IETF - RFC 4627

The “x” in AJAX

Lightweight / simple structures
That was Then ...
JSON for Speed   XML for Integration
JSON Validation

Structure   Instance Document [Well-formed]




Semantics   Schema [Order, Person]
This is Now
JSON for Speed   JSON for Integration
JSON.org
JSON Tutorial - on
   the iPhone
JSON Documents

{
    JSON-Data
}
JSON Data
           Structures
Name/Value (or Key/Value) Pairs


Objects


Arrays
JSON Key/Value Pair

    {
     "firstName": "John"
}
JSON Object
    {
     "address" : {
       "line1" : "555 Main Street",
       "city" : "Denver",
       "stateOrProvince" : "CO",
       "zipOrPostalCode" : "80202",
       "country" : "USA"
     }
}
JSON Array
"clubs" : [
  {
     "number" : 677476,
     "name" : "Simply Speaking",
     "city" : "Aurora",
     "district" : 26
  },
  {
     "number" : 999999,
     "name" : "Wry Toast",
     "city" : "Denver",
     "district" : 26
  }
]
JSON Value Types
Numbers
"age": 29
"cost": 299.99
"temperature": -10.5
"speed_of_light": 1.23e11
"speed_of_light": 1.23e+11
"speed_of_light": 1.23E11
"speed_of_light": 1.23E+11
Booleans


"emailValidated" : true
null
{
    "address": {
        "line1": "555 Main St.",
        "line2": null,
        "city": "Bailey",
        "state": "CO",
        "postalCode": 80909,
        "country": "USA"
    }
}
JSON Comments


     No
JSON Versions


    Never
A Bigger Sample
{
    "member": {
        "firstName": "John",
        "lastName": "Smith",
        "joined": "2008-12-06",
        "language": "US English",
        "reason": "To improve my public speaking skills. To take over the world.",
        "address": {
            "line1": "555 Main St.", "city": "Bailey", "state": "CO",
            "postalCode": 80909, "country": "USA"
        },
        "contact": {
            "email": "john.smith@acme.com", "homePhone": "303-555-1212",
            "cellPhone": "720-555-1212", "workPhone": "970-555-1212"
        },
        "club": {
            "number": 677476, "name": "Simply Speaking",
            "city": "Aurora", "district": 26
        }
    }
}
Google JSON Style
      Guide
JSON is Hot!
JSON Tool Runtimes

                 JSON Tools
                                     iPhone
  GUIs
                                      Apps


                                 Command
      IDE
                                   Line
    Plugins
              Browser   Online
              Plugins
JSON Validators

JSON Validator (Mac)


http://www.jsonlint.com
JSONLint.com
JSON Beautifiers
Firefox     Chrome

JSONView    JSONView

            JSON SH
JSON Without a
  Beautifier
JSONView
JSON SH
JSON Modeling Tools
JSON Designer              http://
                           www.jsonschema.net


JSONPad
                           Overly - Generate
                           Schema

http://
www.jsoneditoronline.org
                           Matic - Generate HTML
JSON Designer - on
   the iPhone
Model JSON Doc -
   JSONPad
Model JSON Doc -
jsoneditoronline.org
JSON and Java -
             Jackson
    public class Address {
    private String line1;
    private String city;
    private String stateOrProvince;
    private String zipOrPostalCode;
    private String country;

    public Address() {}

    public String getLine1() {
        return line1;
    }

    public void setLine1(line1) {
       this.line1 = line1;
    }

    // Remaining getters and setters ...
}

Address addrOut = new Address();
// Call setters to populate addrOut ...
JSON and Java -
        Jackson ... Cont’d
    import java.io.Writer’
import java.io.StringWriter;
import org.codehaus.jackson.map.ObjectMapper;

ObjectMapper mapper = new ObjectMapper(); // Reuse this.

// Marshal Address object to JSON String.
Writer writer = new StringWriter();
mapper.writeValue(writer, addrOut);
System.out.println(writer.toString());

// Unmarshal Address object from JSON String.
String addrJsonStr =
"{" +
     ""address" : {" +
     ""line1" : "555 Main Street"," +
     ""city" : "Denver","
     ""stateOrProvince" : "CO","
     ""zipOrPostalCode" : "80202"," +
     ""country" : "USA"" +
     "}" +
"}";

Address addrIn = mapper.readValue(addrJsonStr, Address.class);
Java-based JSON
                APIs
           API                                     Source

Jackson             http://jackson.codehaus.org/

Google GSON         http://code.google.com/p/google-json/
SOJO                http://sojo.sourceforge.net/
org.json (Douglas   http://www.json.org/java
Crockford)
json-lib            http://sourceforge.net/projects/json-lib/

json-io             http://code.google.com/p/json-io

jsontools           http://jsontools.berlios.de/

jsonbeans           http://code.google.com/p/jsonbeans/
JSON and HTML5 &
      JavaScript - AJAX

       $.getJSON('http://example/service/addresses/home/1',
     function(data) {
       var address = JSON.parse(data);

         console.log(“Address Line 1 = “ + address.line1);
     }
);
JSON and Ruby on
          Rails
    class Person
  attr_accessor :first_name, :last_name

  def initialize(first_name=nil, last_name=nil)
    @first_name = first_name
    @last_name = last_name
  end
end



class MyController < ApplicationController
  def index
    person = Person.new('John', 'Doe')
    respond_to do |format|
      format.html # index.html.erb
      format.json { render :json => person}
    end
  end
end
JSON and Ruby

require 'json'

class Address

  attr_accessor :line1, :city, :state_or_province,
                :zip_or_postal_code, :country

  def initialize(line1=nil, city=nil, state_or_province=nil,
                 zip_or_postal_code=nil, country=nil)
    @line1 = line1
    @city = city
    @state_or_province = state_or_province
    @zip_or_postal_code = zip_or_postal_code
    @country = country
  end
JSON and Ruby
  def to_hash
    hash = {}
    self.instance_variables.each do |var|
      hash[var.to_s.delete("@")] = self.instance_variable_get(var)
    end
    hash
  end

  def to_json
    to_hash.to_json
  end

  def from_json!(str)
    JSON.load(str).each do |var, val|
      self.instance_variable_set("@#{var}", val)
    end
  end
end
JSON and Ruby
    addr1 = Address.new('555 Main Street', 'Denver', 'CO', '80231', 'US')

puts addr1.to_json # Marshal Address object to JSON string.

# Outputs the following …
( "line1": "555 Main Street", "city": "Denver",
"state_or_province": "CO", "zip_or_postal_code": "80231","country":"US" }


json_addr = <<END
{
  "line1" : "999 Broadway", "city" : "Anytown",
  "state_or_province" : "CA", "zip_or_postal_code" : "90210",
  "country" : "USA"
}
END

addr2 = Address.new
addr2.from_json!(json_addr) # Unmarshal Address object from JSON string.
Ruby-based JSON
             APIs
       API                             Source




Yajl         https://github.com/brianmario/yajl-ruby




Oj           https://github.com/ohler55/oj
JSON Schema

Defines JSON document structure


http://json-schema.org/
When To Use JSON
    Schema?


When crossing organizational boundaries
When NOT to use
JSON Schema?


  Get a life - it’s just a website!
JSON Schema
             Constructs
     Construct                        Description

type             The data type – object, array, string, number, etc.


required         true / false


id               Data element id

                 Additional validation properties for a data element (e.g.,
properties
                 minimum, maximum, etc.)
JSON Schema
                 Validators
JSON Schema
            Language Source
Validator

JSV             JavaScript   https://github.com/garycourt/JSV

Ruby JSON
                 Ruby        https://github.com/hoxworth/json-schema
Schema Validator

json-schema-
                Java         https://github.com/fge/json-schema-validator
validator

php-json-schema
                PHP          https://github.com/hasbridge/php-json-schema
(by MIT)

JSON.Net        .NET         http://james.newtonking.com/projects/json-net.aspx
JSON Schema
  Example


Gift Registry Document & Schema
JSON Modeling Flow

    Model      Create   Generate
     JSON      JSON       HTML
   Document   Schema    Document
Create JSON Schema
  - jsonschema.net
Create JSON Schema
      - Orderly
Validate JSON Document
 against JSON Schema
Generate HTML Document
from JSON Schema - Matic
RESTing with JSON
Text Search with
       JSON
JSONQuery


JSONPath


JSONiq
Transforming JSON


JSONT
Our Agenda
What’s The Point?

JSON -
  much
         more ...
Questions?
Tom Marrs

Architect

thomasamarrs@comcast.net

http://www.linkedin.com/in/
TomMarrs

Twitter: @TomMarrs

Skype: t.marrs
JSON Resources
JSON Spec - http://tools.ietf.org/html/rfc4627


JSON.org - http://www.json.org


JSONLint - http://www.jsonlint.com


JSON Editor Online - http://jsoneditoronline.org/
JSON Resources
JSON SH - http://jsonsh.com/



JSON Schema Generator - http://jsonschema.net



JSON Schema Validator - http://json-schema-validator.herokuapp.com/



JSON Schema Spec - http://tools.ietf.org/html/draft-zyp-json-schema-03



Google JSON Style Guide - http://google-styleguide.googlecode.com/svn/trunk/
jsoncstyleguide.xml
JSON Resources
JSONQuery - https://github.com/jcrosby/jsonquery



JSONPath - http://goessner.net/articles/JsonPath/



JSONiq - http://www.jsoniq.org/



JSONT - http://goessner.net/articles/jsont/
JSON Groups
Google - http://groups.google.com/group/json-schema



Yahoo! - http://tech.groups.yahoo.com/group/json/

Más contenido relacionado

La actualidad más candente

Mongo DB schema design patterns
Mongo DB schema design patternsMongo DB schema design patterns
Mongo DB schema design patternsjoergreichert
 
MongoDB Europe 2016 - ETL for Pros – Getting Data Into MongoDB The Right Way
MongoDB Europe 2016 - ETL for Pros – Getting Data Into MongoDB The Right WayMongoDB Europe 2016 - ETL for Pros – Getting Data Into MongoDB The Right Way
MongoDB Europe 2016 - ETL for Pros – Getting Data Into MongoDB The Right WayMongoDB
 
Beyond the Basics 2: Aggregation Framework
Beyond the Basics 2: Aggregation Framework Beyond the Basics 2: Aggregation Framework
Beyond the Basics 2: Aggregation Framework MongoDB
 
The Ruby/mongoDB ecosystem
The Ruby/mongoDB ecosystemThe Ruby/mongoDB ecosystem
The Ruby/mongoDB ecosystemHarold Giménez
 
Jsonsaga 100605143125-phpapp02
Jsonsaga 100605143125-phpapp02Jsonsaga 100605143125-phpapp02
Jsonsaga 100605143125-phpapp02Ramamohan Chokkam
 
"Powerful Analysis with the Aggregation Pipeline (Tutorial)"
"Powerful Analysis with the Aggregation Pipeline (Tutorial)""Powerful Analysis with the Aggregation Pipeline (Tutorial)"
"Powerful Analysis with the Aggregation Pipeline (Tutorial)"MongoDB
 
MongoDB Schema Design: Four Real-World Examples
MongoDB Schema Design: Four Real-World ExamplesMongoDB Schema Design: Four Real-World Examples
MongoDB Schema Design: Four Real-World ExamplesMike Friedman
 
Building web applications with mongo db presentation
Building web applications with mongo db presentationBuilding web applications with mongo db presentation
Building web applications with mongo db presentationMurat Çakal
 
Webinar: Working with Graph Data in MongoDB
Webinar: Working with Graph Data in MongoDBWebinar: Working with Graph Data in MongoDB
Webinar: Working with Graph Data in MongoDBMongoDB
 
Schema Design with MongoDB
Schema Design with MongoDBSchema Design with MongoDB
Schema Design with MongoDBrogerbodamer
 
Webinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in DocumentsWebinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in DocumentsMongoDB
 
Dev Jumpstart: Schema Design Best Practices
Dev Jumpstart: Schema Design Best PracticesDev Jumpstart: Schema Design Best Practices
Dev Jumpstart: Schema Design Best PracticesMongoDB
 
Building a Scalable Inbox System with MongoDB and Java
Building a Scalable Inbox System with MongoDB and JavaBuilding a Scalable Inbox System with MongoDB and Java
Building a Scalable Inbox System with MongoDB and Javaantoinegirbal
 
Real World CouchDB
Real World CouchDBReal World CouchDB
Real World CouchDBJohn Wood
 
MongoDB Aggregations Indexing and Profiling
MongoDB Aggregations Indexing and ProfilingMongoDB Aggregations Indexing and Profiling
MongoDB Aggregations Indexing and ProfilingManish Kapoor
 
Doing More with MongoDB Aggregation
Doing More with MongoDB AggregationDoing More with MongoDB Aggregation
Doing More with MongoDB AggregationMongoDB
 
ETL for Pros: Getting Data Into MongoDB
ETL for Pros: Getting Data Into MongoDBETL for Pros: Getting Data Into MongoDB
ETL for Pros: Getting Data Into MongoDBMongoDB
 
MongoDB Schema Design
MongoDB Schema DesignMongoDB Schema Design
MongoDB Schema DesignMongoDB
 

La actualidad más candente (20)

Json the-x-in-ajax1588
Json the-x-in-ajax1588Json the-x-in-ajax1588
Json the-x-in-ajax1588
 
Mongo DB schema design patterns
Mongo DB schema design patternsMongo DB schema design patterns
Mongo DB schema design patterns
 
MongoDB Europe 2016 - ETL for Pros – Getting Data Into MongoDB The Right Way
MongoDB Europe 2016 - ETL for Pros – Getting Data Into MongoDB The Right WayMongoDB Europe 2016 - ETL for Pros – Getting Data Into MongoDB The Right Way
MongoDB Europe 2016 - ETL for Pros – Getting Data Into MongoDB The Right Way
 
Beyond the Basics 2: Aggregation Framework
Beyond the Basics 2: Aggregation Framework Beyond the Basics 2: Aggregation Framework
Beyond the Basics 2: Aggregation Framework
 
The Ruby/mongoDB ecosystem
The Ruby/mongoDB ecosystemThe Ruby/mongoDB ecosystem
The Ruby/mongoDB ecosystem
 
Jsonsaga 100605143125-phpapp02
Jsonsaga 100605143125-phpapp02Jsonsaga 100605143125-phpapp02
Jsonsaga 100605143125-phpapp02
 
Json
JsonJson
Json
 
"Powerful Analysis with the Aggregation Pipeline (Tutorial)"
"Powerful Analysis with the Aggregation Pipeline (Tutorial)""Powerful Analysis with the Aggregation Pipeline (Tutorial)"
"Powerful Analysis with the Aggregation Pipeline (Tutorial)"
 
MongoDB Schema Design: Four Real-World Examples
MongoDB Schema Design: Four Real-World ExamplesMongoDB Schema Design: Four Real-World Examples
MongoDB Schema Design: Four Real-World Examples
 
Building web applications with mongo db presentation
Building web applications with mongo db presentationBuilding web applications with mongo db presentation
Building web applications with mongo db presentation
 
Webinar: Working with Graph Data in MongoDB
Webinar: Working with Graph Data in MongoDBWebinar: Working with Graph Data in MongoDB
Webinar: Working with Graph Data in MongoDB
 
Schema Design with MongoDB
Schema Design with MongoDBSchema Design with MongoDB
Schema Design with MongoDB
 
Webinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in DocumentsWebinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in Documents
 
Dev Jumpstart: Schema Design Best Practices
Dev Jumpstart: Schema Design Best PracticesDev Jumpstart: Schema Design Best Practices
Dev Jumpstart: Schema Design Best Practices
 
Building a Scalable Inbox System with MongoDB and Java
Building a Scalable Inbox System with MongoDB and JavaBuilding a Scalable Inbox System with MongoDB and Java
Building a Scalable Inbox System with MongoDB and Java
 
Real World CouchDB
Real World CouchDBReal World CouchDB
Real World CouchDB
 
MongoDB Aggregations Indexing and Profiling
MongoDB Aggregations Indexing and ProfilingMongoDB Aggregations Indexing and Profiling
MongoDB Aggregations Indexing and Profiling
 
Doing More with MongoDB Aggregation
Doing More with MongoDB AggregationDoing More with MongoDB Aggregation
Doing More with MongoDB Aggregation
 
ETL for Pros: Getting Data Into MongoDB
ETL for Pros: Getting Data Into MongoDBETL for Pros: Getting Data Into MongoDB
ETL for Pros: Getting Data Into MongoDB
 
MongoDB Schema Design
MongoDB Schema DesignMongoDB Schema Design
MongoDB Schema Design
 

Destacado (7)

Restful design at work v2.0
Restful design at work v2.0Restful design at work v2.0
Restful design at work v2.0
 
Spring insight what just happened
Spring insight   what just happenedSpring insight   what just happened
Spring insight what just happened
 
Redis Clients Handling
Redis Clients HandlingRedis Clients Handling
Redis Clients Handling
 
Big Data and OSS at IBM
Big Data and OSS at IBMBig Data and OSS at IBM
Big Data and OSS at IBM
 
Introduction To Pentaho Kettle
Introduction To Pentaho KettleIntroduction To Pentaho Kettle
Introduction To Pentaho Kettle
 
Introduction To JavaFX 2.0
Introduction To JavaFX 2.0Introduction To JavaFX 2.0
Introduction To JavaFX 2.0
 
Intro to Redis
Intro to RedisIntro to Redis
Intro to Redis
 

Similar a Json at work overview and ecosystem-v2.0

WebSocket JSON Hackday
WebSocket JSON HackdayWebSocket JSON Hackday
WebSocket JSON HackdaySomay Nakhal
 
Introduction to JSON & AJAX
Introduction to JSON & AJAXIntroduction to JSON & AJAX
Introduction to JSON & AJAXRaveendra R
 
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 problemstitanlambda
 
JSON Support in Salesforce - winter 12
JSON Support in Salesforce - winter 12JSON Support in Salesforce - winter 12
JSON Support in Salesforce - winter 12Jitendra Zaa
 
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 2kriszyp
 
json.ppt download for free for college project
json.ppt download for free for college projectjson.ppt download for free for college project
json.ppt download for free for college projectAmitSharma397241
 
Comparing JSON Libraries - July 19 2011
Comparing JSON Libraries - July 19 2011Comparing JSON Libraries - July 19 2011
Comparing JSON Libraries - July 19 2011sullis
 
Mongo Web Apps: OSCON 2011
Mongo Web Apps: OSCON 2011Mongo Web Apps: OSCON 2011
Mongo Web Apps: OSCON 2011rogerbodamer
 
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 Jacksonsrondal
 
Unit-2 JSON.pdf
Unit-2 JSON.pdfUnit-2 JSON.pdf
Unit-2 JSON.pdfhskznx
 
UKOUG Tech14 - Getting Started With JSON in the Database
UKOUG Tech14 - Getting Started With JSON in the DatabaseUKOUG Tech14 - Getting Started With JSON in the Database
UKOUG Tech14 - Getting Started With JSON in the DatabaseMarco Gralike
 

Similar a Json at work overview and ecosystem-v2.0 (20)

Json
JsonJson
Json
 
Advanced Json
Advanced JsonAdvanced Json
Advanced Json
 
WebSocket JSON Hackday
WebSocket JSON HackdayWebSocket JSON Hackday
WebSocket JSON Hackday
 
Json
JsonJson
Json
 
Introduction to JSON & AJAX
Introduction to JSON & AJAXIntroduction to JSON & AJAX
Introduction to JSON & AJAX
 
Hands on JSON
Hands on JSONHands on JSON
Hands on 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
 
Json
JsonJson
Json
 
Json
JsonJson
Json
 
JSON Support in Salesforce - winter 12
JSON Support in Salesforce - winter 12JSON Support in Salesforce - winter 12
JSON Support in Salesforce - winter 12
 
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.ppt download for free for college project
json.ppt download for free for college projectjson.ppt download for free for college project
json.ppt download for free for college project
 
Comparing JSON Libraries - July 19 2011
Comparing JSON Libraries - July 19 2011Comparing JSON Libraries - July 19 2011
Comparing JSON Libraries - July 19 2011
 
Mongo Web Apps: OSCON 2011
Mongo Web Apps: OSCON 2011Mongo Web Apps: OSCON 2011
Mongo Web Apps: OSCON 2011
 
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
 
huhu
huhuhuhu
huhu
 
Drupal Mobile
Drupal MobileDrupal Mobile
Drupal Mobile
 
Unit-2 JSON.pdf
Unit-2 JSON.pdfUnit-2 JSON.pdf
Unit-2 JSON.pdf
 
UKOUG Tech14 - Getting Started With JSON in the Database
UKOUG Tech14 - Getting Started With JSON in the DatabaseUKOUG Tech14 - Getting Started With JSON in the Database
UKOUG Tech14 - Getting Started With JSON in the Database
 
Os Pruett
Os PruettOs Pruett
Os Pruett
 

Json at work overview and ecosystem-v2.0

  • 1. JSON at Work - Overview and Ecosystem Tom Marrs Architect
  • 2. Your Profile Really? What else? How?
  • 3. What’s The Point? JSON - much more ...
  • 4. JSON Ecosystem JSON Core Schema Search Dev Tools APIs REST Transform
  • 6. We’re Not Covering :(- REST XML SOA
  • 7. JSON Beginnings www.json.org 2001 - Douglas Crockford 2006 - IETF - RFC 4627 The “x” in AJAX Lightweight / simple structures
  • 8. That was Then ... JSON for Speed XML for Integration
  • 9. JSON Validation Structure Instance Document [Well-formed] Semantics Schema [Order, Person]
  • 10. This is Now JSON for Speed JSON for Integration
  • 12. JSON Tutorial - on the iPhone
  • 13. JSON Documents { JSON-Data }
  • 14. JSON Data Structures Name/Value (or Key/Value) Pairs Objects Arrays
  • 15. JSON Key/Value Pair { "firstName": "John" }
  • 16. JSON Object { "address" : { "line1" : "555 Main Street", "city" : "Denver", "stateOrProvince" : "CO", "zipOrPostalCode" : "80202", "country" : "USA" } }
  • 17. JSON Array "clubs" : [ { "number" : 677476, "name" : "Simply Speaking", "city" : "Aurora", "district" : 26 }, { "number" : 999999, "name" : "Wry Toast", "city" : "Denver", "district" : 26 } ]
  • 19. Numbers "age": 29 "cost": 299.99 "temperature": -10.5 "speed_of_light": 1.23e11 "speed_of_light": 1.23e+11 "speed_of_light": 1.23E11 "speed_of_light": 1.23E+11
  • 21. null { "address": { "line1": "555 Main St.", "line2": null, "city": "Bailey", "state": "CO", "postalCode": 80909, "country": "USA" } }
  • 23. JSON Versions Never
  • 24. A Bigger Sample { "member": { "firstName": "John", "lastName": "Smith", "joined": "2008-12-06", "language": "US English", "reason": "To improve my public speaking skills. To take over the world.", "address": { "line1": "555 Main St.", "city": "Bailey", "state": "CO", "postalCode": 80909, "country": "USA" }, "contact": { "email": "john.smith@acme.com", "homePhone": "303-555-1212", "cellPhone": "720-555-1212", "workPhone": "970-555-1212" }, "club": { "number": 677476, "name": "Simply Speaking", "city": "Aurora", "district": 26 } } }
  • 27. JSON Tool Runtimes JSON Tools iPhone GUIs Apps Command IDE Line Plugins Browser Online Plugins
  • 28. JSON Validators JSON Validator (Mac) http://www.jsonlint.com
  • 30. JSON Beautifiers Firefox Chrome JSONView JSONView JSON SH
  • 31. JSON Without a Beautifier
  • 34. JSON Modeling Tools JSON Designer http:// www.jsonschema.net JSONPad Overly - Generate Schema http:// www.jsoneditoronline.org Matic - Generate HTML
  • 35. JSON Designer - on the iPhone
  • 36. Model JSON Doc - JSONPad
  • 37. Model JSON Doc - jsoneditoronline.org
  • 38. JSON and Java - Jackson public class Address { private String line1; private String city; private String stateOrProvince; private String zipOrPostalCode; private String country; public Address() {} public String getLine1() { return line1; } public void setLine1(line1) { this.line1 = line1; } // Remaining getters and setters ... } Address addrOut = new Address(); // Call setters to populate addrOut ...
  • 39. JSON and Java - Jackson ... Cont’d import java.io.Writer’ import java.io.StringWriter; import org.codehaus.jackson.map.ObjectMapper; ObjectMapper mapper = new ObjectMapper(); // Reuse this. // Marshal Address object to JSON String. Writer writer = new StringWriter(); mapper.writeValue(writer, addrOut); System.out.println(writer.toString()); // Unmarshal Address object from JSON String. String addrJsonStr = "{" + ""address" : {" + ""line1" : "555 Main Street"," + ""city" : "Denver"," ""stateOrProvince" : "CO"," ""zipOrPostalCode" : "80202"," + ""country" : "USA"" + "}" + "}"; Address addrIn = mapper.readValue(addrJsonStr, Address.class);
  • 40. Java-based JSON APIs API Source Jackson http://jackson.codehaus.org/ Google GSON http://code.google.com/p/google-json/ SOJO http://sojo.sourceforge.net/ org.json (Douglas http://www.json.org/java Crockford) json-lib http://sourceforge.net/projects/json-lib/ json-io http://code.google.com/p/json-io jsontools http://jsontools.berlios.de/ jsonbeans http://code.google.com/p/jsonbeans/
  • 41. JSON and HTML5 & JavaScript - AJAX $.getJSON('http://example/service/addresses/home/1', function(data) { var address = JSON.parse(data); console.log(“Address Line 1 = “ + address.line1); } );
  • 42. JSON and Ruby on Rails class Person attr_accessor :first_name, :last_name def initialize(first_name=nil, last_name=nil) @first_name = first_name @last_name = last_name end end class MyController < ApplicationController def index person = Person.new('John', 'Doe') respond_to do |format| format.html # index.html.erb format.json { render :json => person} end end end
  • 43. JSON and Ruby require 'json' class Address attr_accessor :line1, :city, :state_or_province, :zip_or_postal_code, :country def initialize(line1=nil, city=nil, state_or_province=nil, zip_or_postal_code=nil, country=nil) @line1 = line1 @city = city @state_or_province = state_or_province @zip_or_postal_code = zip_or_postal_code @country = country end
  • 44. JSON and Ruby def to_hash hash = {} self.instance_variables.each do |var| hash[var.to_s.delete("@")] = self.instance_variable_get(var) end hash end def to_json to_hash.to_json end def from_json!(str) JSON.load(str).each do |var, val| self.instance_variable_set("@#{var}", val) end end end
  • 45. JSON and Ruby addr1 = Address.new('555 Main Street', 'Denver', 'CO', '80231', 'US') puts addr1.to_json # Marshal Address object to JSON string. # Outputs the following … ( "line1": "555 Main Street", "city": "Denver", "state_or_province": "CO", "zip_or_postal_code": "80231","country":"US" } json_addr = <<END { "line1" : "999 Broadway", "city" : "Anytown", "state_or_province" : "CA", "zip_or_postal_code" : "90210", "country" : "USA" } END addr2 = Address.new addr2.from_json!(json_addr) # Unmarshal Address object from JSON string.
  • 46. Ruby-based JSON APIs API Source Yajl https://github.com/brianmario/yajl-ruby Oj https://github.com/ohler55/oj
  • 47. JSON Schema Defines JSON document structure http://json-schema.org/
  • 48. When To Use JSON Schema? When crossing organizational boundaries
  • 49. When NOT to use JSON Schema? Get a life - it’s just a website!
  • 50. JSON Schema Constructs Construct Description type The data type – object, array, string, number, etc. required true / false id Data element id Additional validation properties for a data element (e.g., properties minimum, maximum, etc.)
  • 51. JSON Schema Validators JSON Schema Language Source Validator JSV JavaScript https://github.com/garycourt/JSV Ruby JSON Ruby https://github.com/hoxworth/json-schema Schema Validator json-schema- Java https://github.com/fge/json-schema-validator validator php-json-schema PHP https://github.com/hasbridge/php-json-schema (by MIT) JSON.Net .NET http://james.newtonking.com/projects/json-net.aspx
  • 52. JSON Schema Example Gift Registry Document & Schema
  • 53. JSON Modeling Flow Model Create Generate JSON JSON HTML Document Schema Document
  • 54. Create JSON Schema - jsonschema.net
  • 55. Create JSON Schema - Orderly
  • 56. Validate JSON Document against JSON Schema
  • 57. Generate HTML Document from JSON Schema - Matic
  • 59. Text Search with JSON JSONQuery JSONPath JSONiq
  • 62. What’s The Point? JSON - much more ...
  • 64. JSON Resources JSON Spec - http://tools.ietf.org/html/rfc4627 JSON.org - http://www.json.org JSONLint - http://www.jsonlint.com JSON Editor Online - http://jsoneditoronline.org/
  • 65. JSON Resources JSON SH - http://jsonsh.com/ JSON Schema Generator - http://jsonschema.net JSON Schema Validator - http://json-schema-validator.herokuapp.com/ JSON Schema Spec - http://tools.ietf.org/html/draft-zyp-json-schema-03 Google JSON Style Guide - http://google-styleguide.googlecode.com/svn/trunk/ jsoncstyleguide.xml
  • 66. JSON Resources JSONQuery - https://github.com/jcrosby/jsonquery JSONPath - http://goessner.net/articles/JsonPath/ JSONiq - http://www.jsoniq.org/ JSONT - http://goessner.net/articles/jsont/
  • 67. JSON Groups Google - http://groups.google.com/group/json-schema Yahoo! - http://tech.groups.yahoo.com/group/json/