json at work: schema, search, and transform

162
JSON at Work: Schema, Search, and Transform Tom Marrs @TomMarrs

Upload: others

Post on 11-Sep-2021

15 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: JSON at Work: Schema, Search, and Transform

JSON at Work: Schema, Search, and TransformTom Marrs

@TomMarrs

Page 2: JSON at Work: Schema, Search, and Transform

About Me …

Page 3: JSON at Work: Schema, Search, and Transform

What’s The Point?

Drive API Design with JSON Schema

Page 4: JSON at Work: Schema, Search, and Transform

What’s The Point? #2

JSON Search and Transform

Simplify interaction with RESTful APIs

Page 5: JSON at Work: Schema, Search, and Transform

JSON Schema Overview 1Core JSON Schema 2API Design with JSON Schema 3

JSON Search & Transform Overview 4JSON Search 5JSON Transform 6

Agenda

Page 6: JSON at Work: Schema, Search, and Transform

Your Takeaway

Core JSON Schema + JSON Workflow + Really Cool Node Modules :-)

Page 7: JSON at Work: Schema, Search, and Transform

We’re Not Covering

REST

Deep JS

Other Languages

Page 8: JSON at Work: Schema, Search, and Transform

Required Downloads

Local Server http://10.10.32.101

Click on link with my name - Tom Marrs, tmarrs, or whatever

Page 9: JSON at Work: Schema, Search, and Transform

Examples and Slides

https://github.com/tmarrs/presentations/tree/master/OSCON/2015/JSON-at-Work-Schema-Search-and-Transform

Page 10: JSON at Work: Schema, Search, and Transform

JSON Schema Overview 1Core JSON Schema 2API Design with JSON Schema 3

JSON Search & Transform Overview 4JSON Search 5JSON Transform 6

Where Are We?

Page 11: JSON at Work: Schema, Search, and Transform

What is JSON Schema?

Validate Structure + Format

Page 12: JSON at Work: Schema, Search, and Transform

Basic JSON Schema

Page 13: JSON at Work: Schema, Search, and Transform

Basic JSON - Document

Page 14: JSON at Work: Schema, Search, and Transform

JSON Schema Timeline - When?

July 2006

December 2009

March 2010

November 2010

January 2013

October 2013

JSON - RFC 4627

JSON Schema 0.1

JSON Schema 0.2 JSON Schema 0.4

JSON Schema 0.3 JSON - ECMA-404

October 2014

JSON - RFC 7159

Page 15: JSON at Work: Schema, Search, and Transform

The Journey …

Page 16: JSON at Work: Schema, Search, and Transform

json-schema.org

Page 17: JSON at Work: Schema, Search, and Transform

JSON Schema on GitHub

Page 18: JSON at Work: Schema, Search, and Transform

Where Does JSON Schema Fit?

Page 19: JSON at Work: Schema, Search, and Transform

Who uses JSON Schema?

Swagger

Page 20: JSON at Work: Schema, Search, and Transform

Why isn’t JSON Validation Enough?Semantics Syntax

Schema + Instance Document Instance Document

Meaning Well-formed - Valid JSON

Ex: Person, Order { }

Page 21: JSON at Work: Schema, Search, and Transform

Haven’t We Seen This Before?JSON Schema XML Schema

No Reference Instance Document references Schema

No Namespace - Yes! Namespace Misery

.json .xsd

Page 22: JSON at Work: Schema, Search, and Transform

JSON Schema Overview 1Core JSON Schema 2API Design with JSON Schema 3

JSON Search & Transform Overview 4JSON Search 5JSON Transform 6

Where Are We?

Page 23: JSON at Work: Schema, Search, and Transform

Facets of JSON Schema

Page 24: JSON at Work: Schema, Search, and Transform

JSON Schema - Issues and Workflow

Page 25: JSON at Work: Schema, Search, and Transform

My JSON Schema Workflow

Model JSON Document

Validate JSON Document

JSONPad

https://code.google.com/p/json-pad/

Generate JSON Schema

JSON Generator

http://jsonschema.net/

JSON Validate

http://jsonvalidate.com/

JSONLint

http://jsonlint.com

Page 26: JSON at Work: Schema, Search, and Transform

JSONLint

Page 27: JSON at Work: Schema, Search, and Transform

JSON Validate

Page 28: JSON at Work: Schema, Search, and Transform

Beware of Wonky WiFi - Hedge Your Bets!

PDD - Presentation-Driven Development

Page 29: JSON at Work: Schema, Search, and Transform

jsonlint

npm install -g jsonlint

jsonlint basic.json

https://github.com/zaach/jsonlint

Page 30: JSON at Work: Schema, Search, and Transform

ujs-jsonvalidate

npm install -g ujs-jsonvalidate

validate ex-1-basic.json ex-1-basic-schema.json

https://github.com/usingjsonschema/ujs-jsonvalidate-nodejs

Page 31: JSON at Work: Schema, Search, and Transform

JSON Schema - Keywords and Basic Types

Page 32: JSON at Work: Schema, Search, and Transform

Basic KeywordsKeyword Definition

$schemaSpecify JSON Schema version - “$schema": "http://json-schema.org/draft-04/schema#"

type The data type - “type”: “string”

properties The fields for an object

Page 33: JSON at Work: Schema, Search, and Transform

Optional KeywordsKeyword Definition

id (1): Path to field (2): URI to Schema

description For documentation

Page 34: JSON at Work: Schema, Search, and Transform

Basic Types - JSON Schema

Page 35: JSON at Work: Schema, Search, and Transform

Basic Types - JSON Document

Page 36: JSON at Work: Schema, Search, and Transform

Where’s the Validation?Keyword Definition

additionalProperties

enable/disable additional fields in an object

required Which fields are required

additionalItems enable/disable additional array elements

Page 37: JSON at Work: Schema, Search, and Transform

Basic Types Validation - JSON Schema

Page 38: JSON at Work: Schema, Search, and Transform

Validation with Required - JSON Schema

Page 39: JSON at Work: Schema, Search, and Transform

Validation with Required - JSON Doc

Page 40: JSON at Work: Schema, Search, and Transform

Number min/max - JSON Schema

Page 41: JSON at Work: Schema, Search, and Transform

Number min/max - JSON Doc

Page 42: JSON at Work: Schema, Search, and Transform

Simple Array - JSON Schema

Page 43: JSON at Work: Schema, Search, and Transform

Simple Array - JSON Doc

Page 44: JSON at Work: Schema, Search, and Transform

Array min/max - JSON Schema

Page 45: JSON at Work: Schema, Search, and Transform

Array min/max - JSON Doc

Page 46: JSON at Work: Schema, Search, and Transform

Enum - JSON Schema

Page 47: JSON at Work: Schema, Search, and Transform

Enum - JSON Doc

Page 48: JSON at Work: Schema, Search, and Transform

Named Object - JSON Schema

Page 49: JSON at Work: Schema, Search, and Transform

Named Object - JSON Doc

Page 50: JSON at Work: Schema, Search, and Transform

Project 1 - Schema Modeling and Basic Types

projects/README.md#project-1---schema-modeling-and-basic-types

projects/EspressoCON.md

Page 51: JSON at Work: Schema, Search, and Transform

JSON Schema - Constraints

Page 52: JSON at Work: Schema, Search, and Transform

Property Patterns - JSON Schema

Page 53: JSON at Work: Schema, Search, and Transform

Property Patterns - JSON Doc

Page 54: JSON at Work: Schema, Search, and Transform

Regex - JSON Schema

Page 55: JSON at Work: Schema, Search, and Transform

Regex - JSON Doc

Page 56: JSON at Work: Schema, Search, and Transform

Help!! I’m Awful at Regexp! - Regex101

Page 57: JSON at Work: Schema, Search, and Transform

Regular Expressions Info

Page 58: JSON at Work: Schema, Search, and Transform

Regexr

Page 59: JSON at Work: Schema, Search, and Transform

Project 2 - Schema Constraints and Conditional Content

projects/README.md#project-2---schema-constraints-and-conditional-content

projects/EspressoCON.md

Page 60: JSON at Work: Schema, Search, and Transform

JSON Schema - Conditional Content

Page 61: JSON at Work: Schema, Search, and Transform

Dependent Properties - JSON Schema

Page 62: JSON at Work: Schema, Search, and Transform

Dependent Properties - JSON Doc

Page 63: JSON at Work: Schema, Search, and Transform

allOf / anyOf / oneOf

allOf All must match successfully

anyOf One or more to match successfully

oneOf One, and only one, to match successfully

Page 64: JSON at Work: Schema, Search, and Transform

anyOf - JSON Schema

Page 65: JSON at Work: Schema, Search, and Transform

anyOf - JSON Doc

Page 66: JSON at Work: Schema, Search, and Transform

Complex Schemas

Page 67: JSON at Work: Schema, Search, and Transform

References (Internal) - JSON Schema

Page 68: JSON at Work: Schema, Search, and Transform

References (Internal) - JSON Doc

Page 69: JSON at Work: Schema, Search, and Transform

tinyserver

npm install -g tinyserver

tinyserver 8081

Page 70: JSON at Work: Schema, Search, and Transform

References (External) - JSON Schema

Page 71: JSON at Work: Schema, Search, and Transform

References (External) - JSON Schema

Page 72: JSON at Work: Schema, Search, and Transform

References (External) - JSON Doc

Page 73: JSON at Work: Schema, Search, and Transform

JSON Schema Overview 1Core JSON Schema 2API Design with JSON Schema 3

JSON Search & Transform Overview 4JSON Search 5JSON Transform 6

Where Are We?

Page 74: JSON at Work: Schema, Search, and Transform

Real World Use Case

Design/Implement API and Consumer in Parallel

Page 75: JSON at Work: Schema, Search, and Transform

Our Scenario

Leverage JSON Schema to create a Stub REST API …

without any code

Page 76: JSON at Work: Schema, Search, and Transform

My JSON Schema Workflow for APIs

Model JSON Document

Document JSON Schema

(HTML)

Generate JSON Schema

Validate JSON Document

JSONPad

https://code.google.com/p/json-pad/

JSON Schema Generator

http://jsonschema.net/

JSON Validate

http://jsonvalidate.com/

JSONLint

http://jsonlint.com

Matic

https://github.com/mattyod/matic/

Docson

https://github.com/lbovet/docson

Page 77: JSON at Work: Schema, Search, and Transform

JSONPad Demo

Page 78: JSON at Work: Schema, Search, and Transform

JSON Schema Generator Demo

Page 79: JSON at Work: Schema, Search, and Transform

JSON Validate Demo

Page 80: JSON at Work: Schema, Search, and Transform

Maticnpm install -g matic

npm install -g jade

matic

https://github.com/mattyod/matic-draft4-example

https://github.com/mattyod/matic

Page 81: JSON at Work: Schema, Search, and Transform

Matic - Speaker Schema

Page 82: JSON at Work: Schema, Search, and Transform

Docson - Swagger Petstore

https://github.com/lbovet/docson

Page 83: JSON at Work: Schema, Search, and Transform

Swagger Petstore - Regular

Page 84: JSON at Work: Schema, Search, and Transform

My JSON Stub API Workflow

Model JSON Document

Deploy Stub REST API

JSONPad

https://code.google.com/p/json-pad/

Generate JSON Document

JSON Generator

http://www.json-generator.com/

JSON Server

https://github.com/typicode/json-server

Page 85: JSON at Work: Schema, Search, and Transform

JSON Generator Demo

Page 86: JSON at Work: Schema, Search, and Transform

JSON Server - Speakersnpm install -g json-server

json-server -p 5000./speakers.json

http://localhost:5000/speakers

https://github.com/typicode/json-server

Page 87: JSON at Work: Schema, Search, and Transform

Project 3 - API Modeling with Schema

projects/README.md#project-3---api-modeling-with-schema

projects/EspressoCON.md

Page 88: JSON at Work: Schema, Search, and Transform

JSON Schema Overview 1Core JSON Schema 2API Design with JSON Schema 3

JSON Search & Transform Overview 4JSON Search 5JSON Transform 6

Where Are We?

Page 89: JSON at Work: Schema, Search, and Transform

Our Client Stack

Page 90: JSON at Work: Schema, Search, and Transform

Firebase Open Data Set

Page 91: JSON at Work: Schema, Search, and Transform

JSON Server - Airports

json-server -p 5000./airports.json

http://localhost:5000/airports

Page 92: JSON at Work: Schema, Search, and Transform

Airports Stub Service

Page 93: JSON at Work: Schema, Search, and Transform

JSON Search & Transform Rubrik

Page 94: JSON at Work: Schema, Search, and Transform

JSON Schema Overview 1Core JSON Schema 2API Design with JSON Schema 3

JSON Search & Transform Overview 4JSON Search 5JSON Transform 6

Where Are We?

Page 95: JSON at Work: Schema, Search, and Transform

JSON Search Tools

Page 96: JSON at Work: Schema, Search, and Transform

JSONPath

Page 97: JSON at Work: Schema, Search, and Transform

JSONPath Syntax

Page 98: JSON at Work: Schema, Search, and Transform

JSONPath Expression Tester

Page 99: JSON at Work: Schema, Search, and Transform

JSONPath Demo

Page 100: JSON at Work: Schema, Search, and Transform

JSONPath Test

Page 101: JSON at Work: Schema, Search, and Transform

JSONPath ScorecardMindshare Y

Dev Community Y

Platforms JS, Node.js, Java, RoR

Intuitive Y

Standard N

Page 102: JSON at Work: Schema, Search, and Transform

JSON Pointer

Page 103: JSON at Work: Schema, Search, and Transform

JSON Pointer Syntax

Page 104: JSON at Work: Schema, Search, and Transform

JSON Pointer Test

Page 105: JSON at Work: Schema, Search, and Transform

JSON Pointer ScorecardMindshare Y

Dev Community Y

Platforms JS, Node.js, Java, RoR

Intuitive Y

Standard RFC 6901 - Woot!

Page 106: JSON at Work: Schema, Search, and Transform

JSON Query

Page 107: JSON at Work: Schema, Search, and Transform

JSON Query ScorecardMindshare N?

Dev Community N? Possibly Dead

Platforms JS, Node.js

Intuitive Y

Standard N

Page 108: JSON at Work: Schema, Search, and Transform

json:select

Page 109: JSON at Work: Schema, Search, and Transform

json:select Expression Tester

Page 110: JSON at Work: Schema, Search, and Transform

json:select Demo

Page 111: JSON at Work: Schema, Search, and Transform

json:select Test

Page 112: JSON at Work: Schema, Search, and Transform

json:select ScorecardMindshare Y?

Dev Community Y

Platforms JS, Node.js, RoR

Intuitive Y - CSS

Standard N

Page 113: JSON at Work: Schema, Search, and Transform

My JSON Search Choices

API Rank

JSON Pointer 1

JSONPath 2

json:select 3

JSON Query 4

Page 114: JSON at Work: Schema, Search, and Transform

jq

Page 115: JSON at Work: Schema, Search, and Transform

jq play

Page 116: JSON at Work: Schema, Search, and Transform

jq Examples

Page 117: JSON at Work: Schema, Search, and Transform

JSONiq

Page 118: JSON at Work: Schema, Search, and Transform

JSONiq Examples

Page 119: JSON at Work: Schema, Search, and Transform

jq ScorecardMindshare Y

Dev Community Y

Platforms CLI - Linux / Mac OS X / Windows

Intuitive Y

Standard N

Page 120: JSON at Work: Schema, Search, and Transform

JSONiq ScorecardMindshare N

Dev Community Y

Platforms Zorba.io, IBM Data Power

Intuitive Y

Standard N

Page 121: JSON at Work: Schema, Search, and Transform

Project 4 - JSON Search

projects/README.md#project-4---json-search

projects/EspressoCON.md

Page 122: JSON at Work: Schema, Search, and Transform

JSON Schema Overview 1Core JSON Schema 2API Design with JSON Schema 3

JSON Search & Transform Overview 4JSON Search 5JSON Transform 6

Where Are We?

Page 123: JSON at Work: Schema, Search, and Transform

JSON Transform

Page 124: JSON at Work: Schema, Search, and Transform

JSON-T

Page 125: JSON at Work: Schema, Search, and Transform

JSON-T Syntax

Page 126: JSON at Work: Schema, Search, and Transform

JSON-T ScorecardMindshare N

Dev Community N

Platforms JS

Intuitive Y

Standard N

Page 127: JSON at Work: Schema, Search, and Transform

jsonapter

Page 128: JSON at Work: Schema, Search, and Transform

jsonapter Test

Page 129: JSON at Work: Schema, Search, and Transform

jsonapter ScorecardMindshare N

Dev Community Y

Platforms JS, Node.js

Intuitive Y

Standard N

Page 130: JSON at Work: Schema, Search, and Transform

JSON Patch

Page 131: JSON at Work: Schema, Search, and Transform

JSON Patch Standard

Page 132: JSON at Work: Schema, Search, and Transform

JSON Patch Meaning

HTTP PATCH - Partial Updates

Content-Type: application/json-patch+json

Page 133: JSON at Work: Schema, Search, and Transform

JSON Patch Syntax

Page 134: JSON at Work: Schema, Search, and Transform

JSON Patch Test

Page 135: JSON at Work: Schema, Search, and Transform

JSON Patch ScorecardMindshare Y

Dev Community Y

Platforms JS, Node.js, Java, RoR, etc.

Intuitive Y

Standard RFC 6902 - Yes!

Page 136: JSON at Work: Schema, Search, and Transform

Project 5 - JSON Transform

projects/README.md#project-5---json-transform

projects/EspressoCON.md

Page 137: JSON at Work: Schema, Search, and Transform

JSON - XML Conversion Conventions

Page 138: JSON at Work: Schema, Search, and Transform

Badgerfish Convention

Page 139: JSON at Work: Schema, Search, and Transform

Parker Convention

Page 140: JSON at Work: Schema, Search, and Transform

JXON Test - XML -> JSON

Page 141: JSON at Work: Schema, Search, and Transform

JXON Test - JSON -> XML

Page 142: JSON at Work: Schema, Search, and Transform

If All Else Fails … codebeautify.org

Page 143: JSON at Work: Schema, Search, and Transform

JSON Schema Overview 1Core JSON Schema 2API Design with JSON Schema 3

JSON Search & Transform Overview 4JSON Search 5JSON Transform 6

Agenda

Page 144: JSON at Work: Schema, Search, and Transform

What’s The Point?

Drive API Design with JSON Schema

Page 145: JSON at Work: Schema, Search, and Transform

What’s The Point? #2

JSON Search and Transform

Simplify interaction with RESTful APIs

Page 146: JSON at Work: Schema, Search, and Transform

[email protected]

Questions?

Tom Marrs

@TomMarrs

Page 147: JSON at Work: Schema, Search, and Transform

JSON Resources

JSON Spec - http://tools.ietf.org/html/rfc7159

ECMA 404 - http://www.ecma-international.org/publications/standards/Ecma-404.htm

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

JSONLint - http://www.jsonlint.com

Page 148: JSON at Work: Schema, Search, and Transform

JSON Resources

JSON Generator - http://www.json-generator.com/

JSONPad - https://code.google.com/p/json-pad/

JSON Editor Online - http://jsoneditoronline.org/

Page 149: JSON at Work: Schema, Search, and Transform

JSON Schema Resources

json-schema.org - http://json-schema.org/

JSON Schema Spec - http://json-schema.org/latest/json-schema-core.html

JSON Schema Validation Spec - http://json-schema.org/latest/json-schema-validation.html

JSON Hyper-Schema Spec - http://json-schema.org/latest/json-schema-hypermedia.html

Page 150: JSON at Work: Schema, Search, and Transform

Using JSON Schema - http://usingjsonschema.com/

JSON Schema Resources

JSON Validate - http://jsonvalidate.com/

Understanding JSON Schema - http://spacetelescope.github.io/understanding-json-schema/

jsonschema.net - http://jsonschema.net/

IETF - https://tools.ietf.org/html/draft-zyp-json-schema-04

Page 151: JSON at Work: Schema, Search, and Transform

JSON Schema GitHub Repo - https://github.com/kriszyp/json-schema

JSON Schema Resources

JSON Schema Google Group - https://groups.google.com/forum/#!forum/json-schema

Put Some JSON Schema in your life - https://kreuzwerker.de/en/blog/posts/put-some-json-schema-in-your-life

Page 152: JSON at Work: Schema, Search, and Transform

Docson GitHub Repo - https://github.com/lbovet/docson

JSON Schema Resources

Swagger Petstore - http://petstore.swagger.io/#!/pet/getPetById

Docson/Typson Swagger Petstore - http://lbovet.github.io/swagger-ui/dist/index.html#!/pet/getPetById_get_0

Page 153: JSON at Work: Schema, Search, and Transform

JSONPath Resourceshttp://goessner.net/articles/JsonPath/

https://github.com/jayway/JsonPath

https://rubygems.org/gems/jsonpath/versions/0.5.6

https://www.npmjs.com/package/json-path

https://www.npmjs.com/package/jsonpath

Page 154: JSON at Work: Schema, Search, and Transform

JSON Pointer Resourceshttps://tools.ietf.org/html/rfc6901

https://www.npmjs.com/package/json-pointer

https://rubygems.org/gems/json-pointer

https://github.com/fge/jackson-coreutils

http://susanpotter.net/blogs/software/2011/07/why-json-pointer-falls-short/

https://zato.io/blog/posts/json-pointer-rfc-6901.html

Page 155: JSON at Work: Schema, Search, and Transform

JSON Query Resourceshttps://github.com/jcrosby/jsonquery

https://github.com/mmckegg/json-query

https://www.npmjs.com/package/json-query

Page 156: JSON at Work: Schema, Search, and Transform

json:select Resourceshttp://jsonselect.org/#overview

https://github.com/lloyd/JSONSelect

https://github.com/lloyd/JSONSelect/blob/master/JSONSelect.md

https://www.npmjs.com/package/JSONSelect

https://github.com/fd/json_select

Page 157: JSON at Work: Schema, Search, and Transform

JPath Resources

http://bluelinecity.com/software/jpath/

https://www.npmjs.com/package/jpath

https://www.npmjs.com/package/node-jpath

https://github.com/merimond/jpath

Page 158: JSON at Work: Schema, Search, and Transform

jq Resourceshttp://stedolan.github.io/jq/

http://stedolan.github.io/jq/tutorial/

https://github.com/stedolan/jq

https://robots.thoughtbot.com/jq-is-sed-for-json

https://zerokspot.com/weblog/2013/07/18/processing-json-with-jq/

https://jqplay.org/

Page 159: JSON at Work: Schema, Search, and Transform

JSON Transform Resources

http://goessner.net/articles/jsont/

https://github.com/amida-tech/jsonapter

http://codebeautify.org/

Page 160: JSON at Work: Schema, Search, and Transform

JSON Patch Resourceshttp://jsonpatch.com/

https://tools.ietf.org/html/rfc6902

http://jsonpatchjs.com/

https://rubygems.org/gems/json_patch

https://github.com/flipkart-incubator/zjsonpatch

https://www.npmjs.com/package/json-patch

https://www.npmjs.com/package/jsonpatch

Page 161: JSON at Work: Schema, Search, and Transform

JSON - XML Conversion Resources

http://wiki.open311.org/JSON_and_XML_Conversion/

http://badgerfish.ning.com/

https://developer.mozilla.org/en-US/docs/JXON#The_Parker_Convention

http://www.thomasfrank.se/xml_to_json.html

http://www.utilities-online.info/xmltojson/

Page 162: JSON at Work: Schema, Search, and Transform

JSON Groups

Google - http://groups.google.com/group/json-schema

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