• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Json at work   overview and ecosystem-v2.0
 

Json at work overview and ecosystem-v2.0

on

  • 969 views

Slides for Tom Marrs BJUG talk on 2/12/2013. See http://boulderjug.org/2013/01/tuesday-february-12-2013-a-night-with-tom-marrs-covering-json-and-rest.html

Slides for Tom Marrs BJUG talk on 2/12/2013. See http://boulderjug.org/2013/01/tuesday-february-12-2013-a-night-with-tom-marrs-covering-json-and-rest.html

Statistics

Views

Total Views
969
Views on SlideShare
969
Embed Views
0

Actions

Likes
1
Downloads
22
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Json at work   overview and ecosystem-v2.0 Json at work overview and ecosystem-v2.0 Presentation Transcript

    • JSON at Work -Overview and Ecosystem Tom Marrs Architect
    • Your ProfileReally? What else? How?
    • What’s The Point?JSON - much more ...
    • JSON Ecosystem JSON CoreSchema Search Dev Tools APIs REST Transform
    • Our Agenda
    • We’re Not Covering :(-RESTXMLSOA
    • JSON Beginningswww.json.org2001 - Douglas Crockford2006 - IETF - RFC 4627The “x” in AJAXLightweight / simple structures
    • That was Then ...JSON for Speed XML for Integration
    • JSON ValidationStructure Instance Document [Well-formed]Semantics Schema [Order, Person]
    • This is NowJSON for Speed JSON for Integration
    • JSON.org
    • JSON Tutorial - on the iPhone
    • JSON Documents{ JSON-Data}
    • JSON Data StructuresName/Value (or Key/Value) PairsObjectsArrays
    • 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 ValidatorsJSON Validator (Mac)http://www.jsonlint.com
    • JSONLint.com
    • JSON BeautifiersFirefox ChromeJSONView JSONView JSON SH
    • JSON Without a Beautifier
    • JSONView
    • JSON SH
    • JSON Modeling ToolsJSON Designer http:// www.jsonschema.netJSONPad Overly - Generate Schemahttp://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 SourceJackson 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/javaCrockford)json-lib http://sourceforge.net/projects/json-lib/json-io http://code.google.com/p/json-iojsontools 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 endendclass MyController < ApplicationController def index person = Person.new(John, Doe) respond_to do |format| format.html # index.html.erb format.json { render :json => person} end endend
    • JSON and Rubyrequire jsonclass 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 endend
    • 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"}ENDaddr2 = Address.newaddr2.from_json!(json_addr) # Unmarshal Address object from JSON string.
    • Ruby-based JSON APIs API SourceYajl https://github.com/brianmario/yajl-rubyOj https://github.com/ohler55/oj
    • JSON SchemaDefines JSON document structurehttp://json-schema.org/
    • When To Use JSON Schema?When crossing organizational boundaries
    • When NOT to useJSON Schema? Get a life - it’s just a website!
    • JSON Schema Constructs Construct Descriptiontype The data type – object, array, string, number, etc.required true / falseid Data element id Additional validation properties for a data element (e.g.,properties minimum, maximum, etc.)
    • JSON Schema ValidatorsJSON Schema Language SourceValidatorJSV JavaScript https://github.com/garycourt/JSVRuby JSON Ruby https://github.com/hoxworth/json-schemaSchema Validatorjson-schema- Java https://github.com/fge/json-schema-validatorvalidatorphp-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 ExampleGift 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 Documentfrom JSON Schema - Matic
    • RESTing with JSON
    • Text Search with JSONJSONQueryJSONPathJSONiq
    • Transforming JSONJSONT
    • Our Agenda
    • What’s The Point?JSON - much more ...
    • Questions?Tom MarrsArchitectthomasamarrs@comcast.nethttp://www.linkedin.com/in/TomMarrsTwitter: @TomMarrsSkype: t.marrs
    • JSON ResourcesJSON Spec - http://tools.ietf.org/html/rfc4627JSON.org - http://www.json.orgJSONLint - http://www.jsonlint.comJSON Editor Online - http://jsoneditoronline.org/
    • JSON ResourcesJSON SH - http://jsonsh.com/JSON Schema Generator - http://jsonschema.netJSON Schema Validator - http://json-schema-validator.herokuapp.com/JSON Schema Spec - http://tools.ietf.org/html/draft-zyp-json-schema-03Google JSON Style Guide - http://google-styleguide.googlecode.com/svn/trunk/jsoncstyleguide.xml
    • JSON ResourcesJSONQuery - https://github.com/jcrosby/jsonqueryJSONPath - http://goessner.net/articles/JsonPath/JSONiq - http://www.jsoniq.org/JSONT - http://goessner.net/articles/jsont/
    • JSON GroupsGoogle - http://groups.google.com/group/json-schemaYahoo! - http://tech.groups.yahoo.com/group/json/