Slide 1

Slide 1 text

Going Beyond JSON: Representers, ASTs, and Code

Slide 2

Slide 2 text

Hi, I'm Stephen. I've thought way too much about JSON @Stephen_Mizell

Slide 3

Slide 3 text

JSON { "name": "John Doe" }

Slide 4

Slide 4 text

JSONx John Doe

Slide 5

Slide 5 text

Ruby { :name => "John Doe" } Or... json.name "John Doe"

Slide 6

Slide 6 text

Refract { "element": "object", "content": [ { "element": "member", "content": { "key": { "element": "string", "content": "name" }, "value": { "element": "string", "content": "John Doe" } } } ] }

Slide 7

Slide 7 text

These are all instruc.ons to build some internal structure of data.

Slide 8

Slide 8 text

Abstract Source Tree A tree representa*on of the abstract syntac*c structure of source code wri5en in a programming language.

Slide 9

Slide 9 text

Homoiconicity The code and representa.on of the code (AST) is the essen.ally the same

Slide 10

Slide 10 text

Syntax + Structure + Seman.cs + Data Find ways to modularize and compose

Slide 11

Slide 11 text

Instead of JSON -> Applica6on Logic Use JSON -> AST -> Applica2on Logic

Slide 12

Slide 12 text

Treat your formats—JSON and others—as languages. Treat them as DSLs. Parse them to canonical structures decoupled from the format itself.

Slide 13

Slide 13 text

Quick Demo

Slide 14

Slide 14 text

Representers

Slide 15

Slide 15 text

Coupling to HAL { "_links": { "item": { "href": "..." } } } // Get the item link doc._links.item.href

Slide 16

Slide 16 text

Coupling to HAL { "_links": { "item": [ { "href": "..." }, { "href": "..." } ] } } // Broken! doc._links.item.href

Slide 17

Slide 17 text

Using a Representer doc.links.hasRel('item'); doc.links.getByRel('item').first(); Decoupled from structure, syntax, and format.

Slide 18

Slide 18 text

Using a Representer doc.links.add('item', 'http://example.com/1'); doc.links.add('item', 'http://example.com/2'); Decoupled from hypermedia formats. Easy to test what your model is independent of formats.

Slide 19

Slide 19 text

Connascence of Type (CoT)

Slide 20

Slide 20 text

Instead of JSON -> Applica6on Logic Use JSON -> Representer -> Applica5on Logic

Slide 21

Slide 21 text

This provides a clearer boundary between your applica5on and the outside world

Slide 22

Slide 22 text

Your data model is not your object model is not your resource model is not your message model. — Mike Amundsen

Slide 23

Slide 23 text

Real world example GraphQL has an AST. OpenAPI does not.

Slide 24

Slide 24 text

Takeaways • Define boundaries • We shouldn't have breaking changes—clients should just degrade • Consider inputs/outputs as languages • Think about canonical structures for crea?ng unity in a world of diversity